Skip to content

Twitter app added #10

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
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Pedometer
Submodule Pedometer added at d4c2f8
9 changes: 9 additions & 0 deletions TwitterLec12/.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 TwitterLec12/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
37 changes: 37 additions & 0 deletions TwitterLec12/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.apps.nishtha.twitterlec12"
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'
testCompile 'junit:junit:4.12'
compile 'com.android.support:cardview-v7:26.+'
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:support-v4:26.+'
compile 'com.android.support:design:26+'
compile 'com.android.support:recyclerview-v7:26+'
}
25 changes: 25 additions & 0 deletions TwitterLec12/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 /home/nishtha/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.apps.nishtha.twitterlec12;

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.apps.nishtha.twitterlec12", appContext.getPackageName());
}
}
21 changes: 21 additions & 0 deletions TwitterLec12/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.apps.nishtha.twitterlec12">
<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,206 @@
package com.apps.nishtha.twitterlec12;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
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.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

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 {

ProgressDialog progressDialog;
RecyclerView recyclerView;
// Button btnGo;
FloatingActionButton floatingButton;
// EditText editText;
OkHttpClient okHttpClient;
String userName;
String baseUrl = "http://loklak.org/api/search.json?q=";
ArrayList<Statuses> statusesArrayList = new ArrayList<>();
EditText editTextDialog;

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

recyclerView = (RecyclerView) findViewById(R.id.recView);
final TweetAdapter tweetAdapter = new TweetAdapter(statusesArrayList, this);
recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
recyclerView.setAdapter(tweetAdapter);
// btnGo = (Button) findViewById(R.id.btnGo);
okHttpClient = new OkHttpClient();
// editText = (EditText) findViewById(R.id.editText);
floatingButton = (FloatingActionButton) findViewById(R.id.floatingButton);


// statusesArrayList=new ArrayList<>(); //NOT AGAIN! now pointing to a new location other than where Adapter is pointing

floatingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final View v = ((LayoutInflater.from(MainActivity.this))).inflate(R.layout.alert_dialog, null, false);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
alertDialog
.setView(v)
.setTitle("Search tweets")
.setIcon(R.drawable.twitter_icon)
.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
editTextDialog = v.findViewById(R.id.editTextDialog);
userName = editTextDialog.getText().toString();
Request request = new Request.Builder()
.url(baseUrl + userName)
.build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("TAG", "onFailure: " + e.getLocalizedMessage());
}

@Override
public void onResponse(Call call, Response response) throws IOException {

MainActivity.this.runOnUiThread(new Runnable() { //TODO
@Override
public void run() {
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.show();
}
});

String result = response.body().string();
Gson gson = new Gson();
final Tweet tweet = gson.fromJson(result, Tweet.class);

MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
progressDialog.hide();
// Log.d("TAG text : ", "run: " + tweet.getStatuses());
// Log.d("TAG user screen name ", "run: " + tweet.getStatuses().size());
Log.d("TAG size AL ", "run: " + statusesArrayList.size());
if (statusesArrayList.size() != 0) {
statusesArrayList.clear();
tweetAdapter.notifyDataSetChanged();

//All this didnt work!!
// for(int i=0;i<statusesArrayList.size();i++){
// statusesArrayList.remove(i); //why?
// }
// statusesArrayList=new ArrayList<Statuses>();//new lcation in mmemory
// statusesArrayList.removeAll(tweet.getStatuses());


//

}
statusesArrayList.addAll(tweet.getStatuses());
if (statusesArrayList.size() == 0) { //TODO

Toast.makeText(MainActivity.this, "No results found", Toast.LENGTH_SHORT).show();

final Snackbar snackbar = Snackbar.make(new CoordinatorLayout(MainActivity.this), "No results found", Snackbar.LENGTH_SHORT);
snackbar.setAction("Ok", new View.OnClickListener() {
@Override
public void onClick(View view) {
snackbar.dismiss();
}
});
TextView textSnackbar = snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
textSnackbar.setTextColor(Color.CYAN);
snackbar.setActionTextColor(Color.RED);
snackbar.show();
// }
tweetAdapter.notifyDataSetChanged();
}
}
});
}


});
dialogInterface.dismiss();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) { //TODO
Log.d("TAG", "onClick: cancelled");
final Snackbar snackbar = Snackbar.make(new CoordinatorLayout(MainActivity.this), "Cancelled", Snackbar.LENGTH_SHORT);
snackbar.setAction("Ok", new View.OnClickListener() {
@Override
public void onClick(View view) {
snackbar.dismiss();
}
});
snackbar.setActionTextColor(Color.RED);
TextView textViewSnackbar = snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
textViewSnackbar.setTextColor(Color.CYAN);
snackbar.show();
dialogInterface.dismiss();
}
})
.show();
}
});

// btnGo.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// userName = editText.getText().toString();
// Request request = new Request.Builder()
// .url(baseUrl + userName)
// .build();
// okHttpClient.newCall(request).enqueue(new Callback() {
// @Override
// public void onFailure(Call call, IOException e) {
// Log.e("TAG", "onFailure: " + e.getLocalizedMessage());
// }
//
// @Override
// public void onResponse(Call call, Response response) throws IOException {
// String result = response.body().string();
// Gson gson = new Gson();
// final Tweet tweet = gson.fromJson(result, Tweet.class);
//
// MainActivity.this.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// Log.d("TAG text : ", "run: " + tweet.getStatuses());
// Log.d("TAG user screen name ", "run: " + tweet.getStatuses().size());
// statusesArrayList.addAll(tweet.getStatuses());
// tweetAdapter.notifyDataSetChanged();
// }
// });
// }
// });
// }
// });

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.apps.nishtha.twitterlec12;

/**
* Created by nishtha on 7/7/17.
*/

public class Statuses {
String url,text,link;
User user;

public Statuses(String url, String text, String link, User user) {
this.url = url;
this.text = text;
this.link = link;
this.user = user;
}

public String getUrl() {
return url;
}

public String getText() {
return text;
}

public String getLink() {
return link;
}

public User getUser() {
return user;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.apps.nishtha.twitterlec12;

import java.util.ArrayList;

/**
* Created by nishtha on 7/7/17.
*/

public class Tweet {
ArrayList<Statuses> statuses;

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

public Tweet(ArrayList<Statuses> statuses) {

this.statuses = statuses;
}
}
Loading