Skip to content
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

raman #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Twitter/.gitignore
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
1 change: 1 addition & 0 deletions Twitter/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
34 changes: 34 additions & 0 deletions Twitter/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.dell.twitter"
minSdkVersion 21
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.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.code.gson:gson:2.2.2'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:design:25.3.0'
testCompile 'junit:junit:4.12'
}
25 changes: 25 additions & 0 deletions Twitter/app/proguard-rules.pro
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\dell\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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.dell.twitter;

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.dell.twitter", appContext.getPackageName());
}
}
23 changes: 23 additions & 0 deletions Twitter/app/src/main/AndroidManifest.xml
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.dell.twitter">

<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.example.dell.twitter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;

/**
* Created by dell on 7/3/2017.
*/

public class DataAdapter extends BaseAdapter {
ArrayList<Status> dataArrayList;
Context c;

public DataAdapter(ArrayList<Status> dataArrayList, Context c) {
this.dataArrayList = dataArrayList;
this.c = c;
}

@Override
public int getCount() {
return dataArrayList.size();
}

@Override
public Object getItem(int position) {
return null;
}

@Override
public long getItemId(int position) {
return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v;
LayoutInflater layoutInflater= LayoutInflater.from(c);
ViewHolder viewHolder=new ViewHolder();
if (convertView==null) {
v = layoutInflater.inflate(R.layout.single_list_item, parent, false);
viewHolder.name=(TextView)v.findViewById(R.id.name);
viewHolder.user_id=(TextView)v.findViewById(R.id.id);
viewHolder.imageView=(ImageView) v.findViewById(R.id.image);
viewHolder.image=(TextView) v.findViewById(R.id.text);
v.setTag(viewHolder);
}
else
{
v=convertView;
viewHolder=(ViewHolder)v.getTag();
}
Status d = dataArrayList.get(position);
viewHolder.name.setText(d.user.getName());
viewHolder.user_id.setText(d.user.getUser_id());
viewHolder.image.setText(d.getText());
viewHolder.link=d.getLink();
//Log.e("TAGAGAG",d.user.getProfile_image_url_https());
Picasso.with(c).load(d.user.getProfile_image_url_https()).into(viewHolder.imageView);
return v;
}
public class ViewHolder{
ImageView imageView;
String link;
TextView name,user_id,image;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.example.dell.twitter;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

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 {
Button button;
EditText editText;
String s="";
ArrayList<Status> dataArrayList=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button)findViewById(R.id.button);
editText=(EditText)findViewById(R.id.editText);
ListView listView=(ListView)findViewById(R.id.list_view);
final DataAdapter dataAdapter=new DataAdapter(dataArrayList,this);
listView.setAdapter(dataAdapter);
final OkHttpClient okHttpClient = new OkHttpClient();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
s=editText.getText().toString();
editText.setText("");
Request request=new Request.Builder().url("http://loklak.org/api/search.json?timezoneOffset=-330&q="+s).build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("TAG", "onFailure:" );
}

@Override
public void onResponse(Call call, Response response) throws IOException {
String result=response.body().string();
Gson gson=new Gson();
final UserList userList=gson.fromJson(result,UserList.class);
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
dataArrayList.addAll(userList.getStatuses());
Log.e("TAG", "size "+dataArrayList.size() );
dataAdapter.notifyDataSetChanged();
}
});
}
});

}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent=new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(dataArrayList.get(position).getLink()));
startActivity(intent);
}
});
}
}
34 changes: 34 additions & 0 deletions Twitter/app/src/main/java/com/example/dell/twitter/Status.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.dell.twitter;

/**
* Created by dell on 7/7/2017.
*/

public class Status {
User user;
String text,link;

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public String getLink() {
return link;
}

public void setLink(String link) {
this.link = link;
}
}
39 changes: 39 additions & 0 deletions Twitter/app/src/main/java/com/example/dell/twitter/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.dell.twitter;

/**
* Created by dell on 7/7/2017.
*/

public class User {
String name,profile_image_url_https,user_id;

public User(String name, String profile_image_url_https, String user_id) {
this.name = name;
this.profile_image_url_https = profile_image_url_https;
this.user_id = user_id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

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;
}

public String getUser_id() {
return user_id;
}

public void setUser_id(String user_id) {
this.user_id = user_id;
}
}
19 changes: 19 additions & 0 deletions Twitter/app/src/main/java/com/example/dell/twitter/UserList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.dell.twitter;

import java.util.ArrayList;

/**
* Created by dell on 7/7/2017.
*/

public class UserList {
ArrayList<Status> statuses;

public ArrayList<Status> getStatuses() {
return statuses;
}

public void setStatuses(ArrayList<Status> statuses) {
this.statuses = statuses;
}
}
Loading