-
Notifications
You must be signed in to change notification settings - Fork 41
Added Twitter Search App #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ManishSihag
wants to merge
1
commit into
coding-blocks-archives:master
Choose a base branch
from
ManishSihag:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
buildToolsVersion "26.0.0" | ||
defaultConfig { | ||
applicationId "com.example.manish.networkinghw" | ||
minSdkVersion 15 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:26.+' | ||
compile 'com.android.support.constraint:constraint-layout:1.0.2' | ||
compile 'com.squareup.okhttp3:okhttp:3.8.1' | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:cardview-v7:26+' | ||
compile 'com.android.support:recyclerview-v7:26+' | ||
compile 'com.squareup.okhttp3:okhttp:3.8.1' | ||
compile 'com.google.code.gson:gson:2.8.1' | ||
compile 'com.squareup.picasso:picasso:2.5.2' | ||
compile 'com.android.support:design:26+' | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in C:\Users\Manish\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
...gHW/app/src/androidTest/java/com/example/manish/networkinghw/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.manish.networkinghw; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.example.manish.networkinghw", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.manish.networkinghw"> | ||
|
||
<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/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
84 changes: 84 additions & 0 deletions
84
TwitterApp/NetworkingHW/app/src/main/java/com/example/manish/networkinghw/CAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.example.manish.networkinghw; | ||
|
||
import android.content.Context; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.squareup.picasso.Picasso; | ||
|
||
import java.util.ArrayList; | ||
|
||
|
||
/** | ||
* Created by Manish on 26-06-2017. | ||
*/ | ||
|
||
public class CAdapter extends RecyclerView.Adapter<CAdapter.ViewHolder>{ | ||
|
||
|
||
ArrayList arrayList; | ||
Context context; | ||
|
||
|
||
public CAdapter(ArrayList<User> arrayList, Context c) { | ||
|
||
|
||
this.arrayList=arrayList; | ||
this.context=c; | ||
} | ||
|
||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
LayoutInflater li = LayoutInflater.from(context); | ||
View v=li.inflate(R.layout.single_line,parent,false); | ||
ViewHolder vh = new ViewHolder(v); | ||
return vh; | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(ViewHolder holder, int position) { | ||
User c = (User) arrayList.get(position); | ||
|
||
holder.name.setText(c.getScreen_name()); | ||
holder.status.setText(c.getText()); | ||
holder.link.setText(c.getLink()); | ||
holder.like.setText("Likes "+c.getFavourites_count()); | ||
holder.retweet.setText("Retweet "+ c.getRetweet_count()); | ||
Picasso.with(context).load(c.getUser().getProfile_image_url_https()).into(holder.img); | ||
|
||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
@Override | ||
public int getItemCount() { | ||
return arrayList.size(); | ||
} | ||
|
||
public class ViewHolder extends RecyclerView.ViewHolder { | ||
|
||
ImageView img; | ||
TextView name,status,link,like,retweet; | ||
public ViewHolder(View v) { | ||
super(v); | ||
|
||
img=v.findViewById(R.id.image); | ||
name=v.findViewById(R.id.name); | ||
status=v.findViewById(R.id.status); | ||
link=v.findViewById(R.id.link); | ||
like=v.findViewById(R.id.like); | ||
retweet=v.findViewById(R.id.retweet); | ||
|
||
|
||
|
||
|
||
} | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
TwitterApp/NetworkingHW/app/src/main/java/com/example/manish/networkinghw/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.example.manish.networkinghw; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
import okhttp3.Call; | ||
import okhttp3.Callback; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
|
||
|
||
|
||
EditText editText; | ||
Button button; | ||
RecyclerView recyclerView; | ||
|
||
ArrayList<User> arrayList1 = new ArrayList<>(); | ||
|
||
OkHttpClient okHttpClient = new OkHttpClient(); | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
final OkHttpClient okHttpClient=new OkHttpClient(); | ||
|
||
editText= (EditText) findViewById(R.id.editText); | ||
button = (Button)findViewById(R.id.button); | ||
recyclerView = (RecyclerView)findViewById(R.id.recyclerView); | ||
|
||
|
||
RecyclerView.LayoutManager layoutManager= new LinearLayoutManager(this); | ||
recyclerView.setLayoutManager(layoutManager); | ||
final CAdapter adapter = new CAdapter(arrayList1,this); | ||
recyclerView.setAdapter(adapter); | ||
|
||
|
||
|
||
|
||
|
||
button.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
String username=editText.getText().toString(); | ||
final Request request = new Request.Builder() | ||
.url("http://loklak.org/api/search.json?q="+username) | ||
.build(); | ||
|
||
|
||
|
||
okHttpClient.newCall(request).enqueue(new Callback() { | ||
@Override | ||
public void onFailure(Call call, IOException e) { | ||
Log.e("TAG", "onFailure: " + e.getLocalizedMessage()); | ||
Log.e("TAG", "onFailure: " + call.request().url()); | ||
} | ||
|
||
@Override | ||
public void onResponse(Call call, Response response) throws IOException { | ||
arrayList1.clear(); | ||
String result = response.body().string(); | ||
|
||
Gson gson = new Gson(); | ||
|
||
final Status status = gson.fromJson(result, Status.class); | ||
|
||
|
||
// Log.e("TAG", "onResponse: " + users.getarrayList().size()); | ||
|
||
//Notify the adapter for data changes on the UI thread | ||
|
||
MainActivity.this.runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
|
||
arrayList1.addAll(status.getStatuses()); | ||
adapter.notifyDataSetChanged(); | ||
|
||
|
||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
}); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
|
||
|
||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
TwitterApp/NetworkingHW/app/src/main/java/com/example/manish/networkinghw/Status.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.manish.networkinghw; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by Manish on 07-07-2017. | ||
*/ | ||
|
||
public class Status { | ||
|
||
|
||
ArrayList<User> statuses = new ArrayList<>(); | ||
|
||
public Status(ArrayList<User> statuses) { | ||
this.statuses = statuses; | ||
} | ||
|
||
public ArrayList<User> getStatuses() { | ||
return statuses; | ||
} | ||
|
||
public void setStatuses(ArrayList<User> statuses) { | ||
this.statuses = statuses; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try not to leave unnecessary empty lines in your project.