Skip to content

Commit

Permalink
The final submission for API Digest 2021
Browse files Browse the repository at this point in the history
  • Loading branch information
Devansh committed Feb 26, 2021
1 parent 2b65770 commit 6b74ea0
Show file tree
Hide file tree
Showing 49 changed files with 1,420 additions and 59 deletions.
6 changes: 6 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation 'com.android.volley:volley:1.1.1'

implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.mikhaellopez:circularimageview:4.2.0'

}
42 changes: 29 additions & 13 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android = "http://schemas.android.com/apk/res/android"
package = "com.example.rickrolled">
<uses-permission android:name = "android.permission.INTERNET"/>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rickrolled">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup = "true"
android:icon = "@mipmap/ic_launcher"
android:label = "@string/app_name"
android:roundIcon = "@mipmap/ic_launcher_round"
android:supportsRtl = "true"
android:theme = "@style/Theme.Rickrolled">
<activity android:name = ".MainActivity">
android:allowBackup="true"
android:icon="@mipmap/app_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/app_icon_round"
android:supportsRtl="true"
android:theme="@style/Theme.Rickrolled">

<activity android:name=".RickrollMe"
android:theme="@style/Theme.AppCompat.NoActionBar"/>

<activity android:name=".TreeActivity" />

<activity
android:name=".EndSplash"
android:theme="@style/EndSplash" />

<activity
android:name=".SplashScreen"
android:theme="@style/Splash">
<intent-filter>
<action android:name = "android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN" />

<category android:name = "android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".MainActivity"
android:label="@string/app_name" />
</application>

</manifest>
37 changes: 37 additions & 0 deletions app/src/main/java/com/example/rickrolled/EndSplash.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.rickrolled;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

public class EndSplash extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_end_splash);

ImageView endSplash = findViewById(R.id.endSplash);
Glide.with(getApplicationContext())
.asGif()
.load(R.drawable.exhausted)
.into(endSplash);

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
finish();
}
}, 5000);
}

@Override
public void onBackPressed() {
Toast.makeText(this, "hold up child, people are grieving", Toast.LENGTH_SHORT).show();
}
}
71 changes: 71 additions & 0 deletions app/src/main/java/com/example/rickrolled/InfoFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.example.rickrolled;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.StringRequest;
import com.bumptech.glide.Glide;

public class InfoFragment extends Fragment {

private TextView name, gender, species, status, origin, lastknown;
private String img;
private ImageView view;
public InfoFragment() {
// Required empty public constructor
}
//
// public InfoFragment(String name, String gender, String species, String status, String origin, String lastknown, String img){
// this.name.setText(name);
// this.gender.setText(gender);
// this.species.setText(species);
// this.status.setText(status);
// this.origin.setText(origin);
// this.lastknown.setText(lastknown);
// this.img = img;
// }

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v= inflater.inflate(R.layout.fragment_info, container, false);

name=v.findViewById(R.id.charname);
gender=v.findViewById(R.id.chargender);
species=v.findViewById(R.id.charspecies);
status=v.findViewById(R.id.charstatus);
origin=v.findViewById(R.id.charorigin);
lastknown=v.findViewById(R.id.charlastknown);
img="";
view=v.findViewById(R.id.charimage);

name.setText(getArguments().getString("name"));
gender.setText(getArguments().getString("gender"));
species.setText(getArguments().getString("species"));
status.setText(getArguments().getString("status"));
origin.setText(getArguments().getString("origin"));
lastknown.setText(getArguments().getString("location"));

Glide.with(getActivity().getApplicationContext())
.asBitmap()
.load(getArguments().getString("image"))
.into(view);



return v;
}
}
131 changes: 109 additions & 22 deletions app/src/main/java/com/example/rickrolled/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,68 +1,155 @@
package com.example.rickrolled;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.bumptech.glide.Glide;
import com.google.android.material.progressindicator.LinearProgressIndicator;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

public class MainActivity extends AppCompatActivity {

private Toolbar toolbar;
RecyclerView charView;
JSONObject jsonObject;
JSONArray jsonArray;
Button button, buttonnext, buttonprev, btn;
ImageView sparkyHome;
LinearProgressIndicator progressIndicator;
private static final String TAG = "MainActivity";
private static final String URL = "https://rickandmortyapi.com/api/character";
private TextView textView;
private String CHAR_URL = "https://rickandmortyapi.com/api/character";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textView=findViewById(R.id.tvresult);
toolbar = findViewById(R.id.hometoolbar);
setSupportActionBar(toolbar);

button = findViewById(R.id.rick_roll);
buttonnext = findViewById(R.id.next);
buttonprev = findViewById(R.id.prev);
sparkyHome = findViewById(R.id.sparkyhome);

Glide.with(this)
.asGif()
.load(R.drawable.sparky)
.into(sparkyHome);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getApplicationContext(), RickrollMe.class));
}
});
progressIndicator = findViewById(R.id.progressbar);
getjson();
}

StringRequest stringRequest=new StringRequest(Request.Method.GET,
URL,
public void getjson() {
StringRequest stringRequest = new StringRequest(Request.Method.GET, CHAR_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject=new JSONObject(response);
JSONArray jsonArray=jsonObject.getJSONArray("results");

for(int i=0;i<jsonArray.length();++i){
JSONObject o=jsonArray.getJSONObject(i);
String s=o.getString("name")+"\n"+
o.getString("status")+"\n\n";
textView.append(s);
}

jsonObject = new JSONObject(response);
jsonArray = jsonObject.getJSONArray("results");
} catch (JSONException e) {
e.printStackTrace();
Log.d(TAG, "onResponse: "+e.getMessage());
Log.d(TAG, "onResponse: " + e.getMessage());
} finally {
charView = findViewById(R.id.charView);
RVAdapter rva = new RVAdapter(getApplicationContext(), jsonArray);
charView.setAdapter(rva);
charView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
progressIndicator.setVisibility(View.GONE);
buttonnext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
progressIndicator.setVisibility(View.VISIBLE);
CHAR_URL = jsonObject.getJSONObject("info").getString("next");
if (CHAR_URL != null)
getjson();
else
Toast.makeText(MainActivity.this, "Doesn't exist", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
buttonprev.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
progressIndicator.setVisibility(View.VISIBLE);
CHAR_URL = jsonObject.getJSONObject("info").getString("prev");
Log.d(TAG, "onClick: 123" + CHAR_URL);
if (!CHAR_URL.equals("null")) {
getjson();
} else {
Toast.makeText(MainActivity.this, "Doesn't exist", Toast.LENGTH_SHORT).show();
progressIndicator.setVisibility(View.GONE);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
});

RequestQueue requestQueue= Volley.newRequestQueue(this);
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
requestQueue.add(stringRequest);
}

@Override
public void onBackPressed() {
super.onBackPressed();
startActivity(new Intent(this, EndSplash.class));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.home_menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.family_tree) {
startActivity(new Intent(getApplicationContext(), TreeActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
}
Loading

0 comments on commit 6b74ea0

Please sign in to comment.