diff --git a/TwitterGo b/TwitterGo new file mode 160000 index 0000000..1de5826 --- /dev/null +++ b/TwitterGo @@ -0,0 +1 @@ +Subproject commit 1de58268fa0ae1e34ccf98738b3a8627e9bb2906 diff --git a/TwitterSearch/.gitignore b/TwitterSearch/.gitignore new file mode 100644 index 0000000..39fb081 --- /dev/null +++ b/TwitterSearch/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/TwitterSearch/app/.gitignore b/TwitterSearch/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/TwitterSearch/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/TwitterSearch/app/build.gradle b/TwitterSearch/app/build.gradle new file mode 100644 index 0000000..3a9e88c --- /dev/null +++ b/TwitterSearch/app/build.gradle @@ -0,0 +1,36 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.3" + defaultConfig { + applicationId "com.codingblocks.gurleen.twittergo" + minSdkVersion 16 + targetSdkVersion 25 + 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:25.3.1' + compile 'com.android.support.constraint:constraint-layout:1.0.2' + testCompile 'junit:junit:4.12' + 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:25.3.1' + testCompile 'junit:junit:4.12' + compile 'com.android.support:cardview-v7:25.3.1' +} diff --git a/TwitterSearch/app/proguard-rules.pro b/TwitterSearch/app/proguard-rules.pro new file mode 100644 index 0000000..2a08cee --- /dev/null +++ b/TwitterSearch/app/proguard-rules.pro @@ -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\hp\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 diff --git a/TwitterSearch/app/src/androidTest/java/com/codingblocks/gurleen/twittergo/ExampleInstrumentedTest.java b/TwitterSearch/app/src/androidTest/java/com/codingblocks/gurleen/twittergo/ExampleInstrumentedTest.java new file mode 100644 index 0000000..e354d71 --- /dev/null +++ b/TwitterSearch/app/src/androidTest/java/com/codingblocks/gurleen/twittergo/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.codingblocks.gurleen.twittergo; + +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 Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.codingblocks.gurleen.twittergo", appContext.getPackageName()); + } +} diff --git a/TwitterSearch/app/src/main/AndroidManifest.xml b/TwitterSearch/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d42dbda --- /dev/null +++ b/TwitterSearch/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TwitterSearch/app/src/main/ic_launcher-web.png b/TwitterSearch/app/src/main/ic_launcher-web.png new file mode 100644 index 0000000..9dace46 Binary files /dev/null and b/TwitterSearch/app/src/main/ic_launcher-web.png differ diff --git a/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/MainActivity.java b/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/MainActivity.java new file mode 100644 index 0000000..fd392ad --- /dev/null +++ b/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/MainActivity.java @@ -0,0 +1,135 @@ +package com.codingblocks.gurleen.twittergo; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +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 { + + Request request; + EditText ed; + Button b; + String username; + String api; + Callback callback; + RecyclerView rv; + results resultobj; + OkHttpClient okHttpClient; + MyAdapter myAdapter; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + ed = (EditText)findViewById(R.id.textv); + b=(Button)findViewById(R.id.searchb); + api= "https://loklak.org/api/search.json?q="; + okHttpClient = new OkHttpClient(); + rv=(RecyclerView)findViewById(R.id.rv); + RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); + rv.setLayoutManager(layoutManager); + + b.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + username = ed.getText().toString(); + request = new Request.Builder() + .url(api+username) + .build(); + okHttpClient.newCall(request).enqueue(callback); + + + } + }); + + + + callback = 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 { + String result = response.body().string(); + Log.e("TAG", "" + result); + Gson gson = new Gson(); + + resultobj = gson.fromJson(result,results.class); + + + //Notify the adapter for data changes on the UI thread + + MainActivity.this.runOnUiThread(new Runnable() { + @Override + public void run() { + myAdapter = new MyAdapter(resultobj,MainActivity.this); + rv.setAdapter(myAdapter);} + }); + } + }; }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/MyAdapter.java b/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/MyAdapter.java new file mode 100644 index 0000000..d9d43bb --- /dev/null +++ b/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/MyAdapter.java @@ -0,0 +1,112 @@ +package com.codingblocks.gurleen.twittergo; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.support.design.widget.FloatingActionButton; +import android.support.v4.content.ContextCompat; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageButton; +import android.widget.TextView; + +import com.squareup.picasso.Picasso; + +import org.w3c.dom.Text; + +import java.util.ArrayList; + +/** + * Created by hp on 7/8/2017. + */ + +public class MyAdapter extends RecyclerView.Adapter { + + + results obj = new results(new ArrayList()); + Context c; + ArrayList arrayList=new ArrayList<>(); + + public MyAdapter(results obj, Context c) + + { + + this.obj = obj; + this.c = c; + arrayList=obj.getStatuses(); + } + + @Override + public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + LayoutInflater l = LayoutInflater.from(c); + View v = l.inflate(R.layout.rowlayout, parent, false); + ViewHolder vh = new ViewHolder(v); + return vh; + } + + + @Override + public void onBindViewHolder(MyAdapter.ViewHolder holder, int position) { + final status s = arrayList.get(position); + // Gson gson = new Gson(); + // String currentUser = gson.toJson(position); + Picasso.with(c).load(s.getUser().getProfile_image_url_https()) + .placeholder(R.mipmap.ic_launcher) + .into(holder.ib); + if(position%2==0) + holder.itemView.setBackgroundColor(ContextCompat.getColor(c,R.color.one)); + else + holder.itemView.setBackgroundColor(ContextCompat.getColor(c,R.color.two)); + + holder.name.setText(s.getScreen_name()); + holder.tweet.setText(s.getText()); +holder.retweets.setText(s.getRetweet_count()); + holder.likes.setText(s.getFavourites_count()); + + holder.tweet.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(s.getLink())); + + c.startActivity(i); + } + }); + + } + + @Override + public int getItemCount() { + + + if (arrayList.size() != 0) + return arrayList.size(); + else return 0; + } + + + public class ViewHolder extends RecyclerView.ViewHolder { + ImageButton ib; + TextView name, tweet,retweets,likes; + ImageButton fb; + + + public ViewHolder(View itemView) { + + + super(itemView); + ib = (ImageButton) itemView.findViewById(R.id.face); + name = (TextView) itemView.findViewById(R.id.name); + tweet = (TextView) itemView.findViewById(R.id.tweet); + +retweets=(TextView)itemView.findViewById(R.id.retweets); + likes=(TextView)itemView.findViewById(R.id.likes); + + } + + + } + + +} diff --git a/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/Userdata.java b/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/Userdata.java new file mode 100644 index 0000000..3b557cc --- /dev/null +++ b/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/Userdata.java @@ -0,0 +1,40 @@ +package com.codingblocks.gurleen.twittergo; + +/** + * Created by hp on 7/8/2017. + */ + +public class Userdata { + + String profile_image_url_https; + + + public Userdata(String profile_image_url_https) { + this.profile_image_url_https = profile_image_url_https; + } + + + public String getProfile_image_url_https() { + return profile_image_url_https; + } + + + public void setProfile_image_url_https(String profile_image_url_https) { + this.profile_image_url_https = profile_image_url_https; + } + + + + + + + + + + + + + + + +} diff --git a/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/results.java b/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/results.java new file mode 100644 index 0000000..f931902 --- /dev/null +++ b/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/results.java @@ -0,0 +1,23 @@ +package com.codingblocks.gurleen.twittergo; + +import java.util.ArrayList; + +/** + * Created by hp on 7/8/2017. + */ + +public class results { + ArrayList statuses; + + public results(ArrayList statuses) { + this.statuses = statuses; + } + + public void setStatuses(ArrayList statuses) { + this.statuses = statuses; + } + + public ArrayList getStatuses() { + return statuses; + } +} diff --git a/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/status.java b/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/status.java new file mode 100644 index 0000000..2fe5af9 --- /dev/null +++ b/TwitterSearch/app/src/main/java/com/codingblocks/gurleen/twittergo/status.java @@ -0,0 +1,83 @@ +package com.codingblocks.gurleen.twittergo; + +/** + * Created by hp on 7/8/2017. + */ + +public class status { + + + + String text; + String link; + + public void setRetweet_count(String retweet_count) { + this.retweet_count = retweet_count; + } + + public void setFavourites_count(String favourites_count) { + this.favourites_count = favourites_count; + } + + String screen_name; + Userdata user; + String retweet_count; + String favourites_count; + + public String getRetweet_count() { + return retweet_count; + } + + public String getFavourites_count() { + return favourites_count; + } + + public Userdata getUser() { + return user; + } + + + public status(String text, String link, String screen_name, Userdata user, String retweet_count, String favourites_count) { + this.text = text; + this.link = link; + this.screen_name = screen_name; + this.user = user; + this.retweet_count = retweet_count; + this.favourites_count = favourites_count; + } + + public void setLink(String link) { + this.link = link; + } + + public void setScreen_name(String screen_name) { + this.screen_name = screen_name; + } + + public void setUser(Userdata user) { + this.user = user; + } + + public String getText() { + return text; + } + + public String getLink() { + return link; + } + + public String getScreen_name() { + return screen_name; + } + + + public void setText(String text) { + this.text = text; + } + + + + + + +} diff --git a/TwitterSearch/app/src/main/res/drawable/heart.jpg b/TwitterSearch/app/src/main/res/drawable/heart.jpg new file mode 100644 index 0000000..bdd38ab Binary files /dev/null and b/TwitterSearch/app/src/main/res/drawable/heart.jpg differ diff --git a/TwitterSearch/app/src/main/res/drawable/retweet.png b/TwitterSearch/app/src/main/res/drawable/retweet.png new file mode 100644 index 0000000..2e2f390 Binary files /dev/null and b/TwitterSearch/app/src/main/res/drawable/retweet.png differ diff --git a/TwitterSearch/app/src/main/res/drawable/searc.png b/TwitterSearch/app/src/main/res/drawable/searc.png new file mode 100644 index 0000000..cc544e1 Binary files /dev/null and b/TwitterSearch/app/src/main/res/drawable/searc.png differ diff --git a/TwitterSearch/app/src/main/res/drawable/search.png b/TwitterSearch/app/src/main/res/drawable/search.png new file mode 100644 index 0000000..bfa893a Binary files /dev/null and b/TwitterSearch/app/src/main/res/drawable/search.png differ diff --git a/TwitterSearch/app/src/main/res/drawable/twit.png b/TwitterSearch/app/src/main/res/drawable/twit.png new file mode 100644 index 0000000..1ad38f2 Binary files /dev/null and b/TwitterSearch/app/src/main/res/drawable/twit.png differ diff --git a/TwitterSearch/app/src/main/res/drawable/twitter.png b/TwitterSearch/app/src/main/res/drawable/twitter.png new file mode 100644 index 0000000..584ac7d Binary files /dev/null and b/TwitterSearch/app/src/main/res/drawable/twitter.png differ diff --git a/TwitterSearch/app/src/main/res/layout/activity_main.xml b/TwitterSearch/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..070588f --- /dev/null +++ b/TwitterSearch/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,86 @@ + + + + + + + + + +