This commit is contained in:
NudeDude 2018-01-01 18:34:37 +01:00
parent 0be9ac2dcc
commit 0cbb4d149e
22 changed files with 272 additions and 100 deletions

View File

@ -13,12 +13,12 @@ public class ImageDownloader extends AsyncTask<String, Void, Bitmap>
{ {
private ImageView imgView; private ImageView imgView;
public ImageDownloader(ImageView imgView){ public ImageDownloader(ImageView imgView) {
this.imgView = imgView; this.imgView = imgView;
} }
@Override @Override
protected Bitmap doInBackground(String... links){ protected Bitmap doInBackground(String... links) {
Bitmap picture = null; Bitmap picture = null;
try { try {
@ -31,7 +31,7 @@ public class ImageDownloader extends AsyncTask<String, Void, Bitmap>
} }
@Override @Override
protected void onPostExecute(Bitmap img){ protected void onPostExecute(Bitmap img) {
imgView.setImageBitmap(img); imgView.setImageBitmap(img);
} }
} }

View File

@ -7,6 +7,7 @@ import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.ViewAdapter.TimelineAdapter; import org.nuclearfog.twidda.ViewAdapter.TimelineAdapter;
import org.nuclearfog.twidda.ViewAdapter.TrendAdapter; import org.nuclearfog.twidda.ViewAdapter.TrendAdapter;
import android.content.SharedPreferences;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
@ -26,6 +27,8 @@ public class MainPage extends AsyncTask<Integer, Void, Boolean>
private ListView timelineList, trendList, mentionList; private ListView timelineList, trendList, mentionList;
private TimelineAdapter timelineAdapter, mentionAdapter; private TimelineAdapter timelineAdapter, mentionAdapter;
private TrendAdapter trendsAdapter; private TrendAdapter trendsAdapter;
private SharedPreferences settings;
private int load;
/** /**
@ -35,7 +38,9 @@ public class MainPage extends AsyncTask<Integer, Void, Boolean>
public MainPage(Context context) { public MainPage(Context context) {
this.context=context; this.context=context;
twitterResource = TwitterResource.getInstance(context); twitterResource = TwitterResource.getInstance(context);
twitterResource.init(); twitterResource.init();// preload
settings = context.getSharedPreferences("settings", 0);
load = settings.getInt("preload", 10);
} }
@Override @Override
@ -58,15 +63,16 @@ public class MainPage extends AsyncTask<Integer, Void, Boolean>
@Override @Override
protected Boolean doInBackground(Integer... args) { protected Boolean doInBackground(Integer... args) {
Twitter twitter = twitterResource.getTwitter(); Twitter twitter = twitterResource.getTwitter();
Paging p = new Paging(); //TODO Paging p = new Paging();
p.setCount(100); p.setCount(load);
try { try {
if(args[0]==0) { if(args[0]==0) {
TweetDatabase mTweets = new TweetDatabase(twitter.getHomeTimeline(p), context,TweetDatabase.HOME_TL,0); TweetDatabase mTweets = new TweetDatabase(twitter.getHomeTimeline(p), context,TweetDatabase.HOME_TL,0);
timelineAdapter = new TimelineAdapter(context,mTweets); timelineAdapter = new TimelineAdapter(context,mTweets);
} }
else if(args[0]==1) { else if(args[0]==1) {
TrendDatabase trend = new TrendDatabase(twitter.getPlaceTrends(23424829),context); //Germany by default int location = settings.getInt("woeid",23424829);
TrendDatabase trend = new TrendDatabase(twitter.getPlaceTrends(location),context); //Germany by default
trendsAdapter = new TrendAdapter(context,trend); trendsAdapter = new TrendAdapter(context,trend);
} }
else if(args[0]==2) { else if(args[0]==2) {

View File

@ -22,7 +22,7 @@ public class ProfileInfo extends AsyncTask<Long,Void,Void>
private boolean imgEnabled = false; private boolean imgEnabled = false;
/** /**
* @param context "this" Context * @param context Activity's Context
*/ */
public ProfileInfo(Context context) { public ProfileInfo(Context context) {
this.context=context; this.context=context;

View File

@ -1,6 +1,7 @@
package org.nuclearfog.twidda.Backend; package org.nuclearfog.twidda.Backend;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ListView; import android.widget.ListView;
@ -10,6 +11,7 @@ import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.ViewAdapter.TimelineAdapter; import org.nuclearfog.twidda.ViewAdapter.TimelineAdapter;
import org.nuclearfog.twidda.Window.UserProfile; import org.nuclearfog.twidda.Window.UserProfile;
import twitter4j.Paging;
import twitter4j.Twitter; import twitter4j.Twitter;
public class ProfileTweets extends AsyncTask<Long, Void, Void> { public class ProfileTweets extends AsyncTask<Long, Void, Void> {
@ -19,11 +21,15 @@ public class ProfileTweets extends AsyncTask<Long, Void, Void> {
private ListView profileTweets, profileFavorits; private ListView profileTweets, profileFavorits;
private TwitterResource twitterResource; private TwitterResource twitterResource;
private TimelineAdapter homeTl, homeFav; private TimelineAdapter homeTl, homeFav;
private SharedPreferences settings;
private int load;
public ProfileTweets(Context context){ public ProfileTweets(Context context){
this.context=context; this.context=context;
twitterResource = TwitterResource.getInstance(context); twitterResource = TwitterResource.getInstance(context);
twitterResource.init(); twitterResource.init();
settings = context.getSharedPreferences("settings", 0);
load = settings.getInt("preload", 10);
} }
/** /**
@ -45,12 +51,14 @@ public class ProfileTweets extends AsyncTask<Long, Void, Void> {
protected Void doInBackground(Long... id) { protected Void doInBackground(Long... id) {
try { try {
long userId = id[0]; long userId = id[0];
Paging p = new Paging();
p.setCount(load);
Twitter twitter = twitterResource.getTwitter(); Twitter twitter = twitterResource.getTwitter();
if(id[1] == 0) { if(id[1] == 0) {
TweetDatabase hTweets = new TweetDatabase(twitter.getUserTimeline(userId), context,TweetDatabase.USER_TL,userId); TweetDatabase hTweets = new TweetDatabase(twitter.getUserTimeline(userId,p), context,TweetDatabase.USER_TL,userId);
homeTl = new TimelineAdapter(context,hTweets); homeTl = new TimelineAdapter(context,hTweets);
} else if(id[1] == 1) { } else if(id[1] == 1) {
TweetDatabase fTweets = new TweetDatabase(twitter.getFavorites(userId), context,TweetDatabase.FAV_TL,userId); TweetDatabase fTweets = new TweetDatabase(twitter.getFavorites(userId,p), context,TweetDatabase.FAV_TL,userId);
homeFav = new TimelineAdapter(context,fTweets); homeFav = new TimelineAdapter(context,fTweets);
} }
} catch(Exception err){err.printStackTrace();} } catch(Exception err){err.printStackTrace();}

View File

@ -21,7 +21,7 @@ public class RegisterAccount extends AsyncTask<String, Void, String>
* @see TwitterResource used to Store Twitter instance * @see TwitterResource used to Store Twitter instance
* @param context current Activity's Context. * @param context current Activity's Context.
*/ */
public RegisterAccount( Context context ){ public RegisterAccount(Context context) {
this.context = context; this.context = context;
} }

View File

@ -53,6 +53,5 @@ public class Search extends AsyncTask<String, Void, Boolean> {
@Override @Override
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean result) {
tl.setAdapter(tlAdp); tl.setAdapter(tlAdp);
} }
} }

View File

@ -5,7 +5,6 @@ import android.os.AsyncTask;
import android.widget.Toast; import android.widget.Toast;
import twitter4j.Twitter; import twitter4j.Twitter;
import twitter4j.TwitterException;
public class SendStatus extends AsyncTask<String, Void, Boolean> { public class SendStatus extends AsyncTask<String, Void, Boolean> {
@ -34,8 +33,9 @@ public class SendStatus extends AsyncTask<String, Void, Boolean> {
twitter.tweets().updateStatus(tweet); twitter.tweets().updateStatus(tweet);
return true; return true;
} }
}catch(TwitterException err){} } catch(Exception err) {
catch(Exception err){} err.printStackTrace();
}
return false; return false;
} }
@ -43,6 +43,8 @@ public class SendStatus extends AsyncTask<String, Void, Boolean> {
protected void onPostExecute(Boolean success) { protected void onPostExecute(Boolean success) {
if(success) { if(success) {
Toast.makeText(context, "TweetDetail wurde gesendet!", Toast.LENGTH_LONG).show(); Toast.makeText(context, "TweetDetail wurde gesendet!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "Fehler beim Senden des Tweets!", Toast.LENGTH_LONG).show();
} }
} }
} }

View File

@ -1,6 +1,7 @@
package org.nuclearfog.twidda.Backend; package org.nuclearfog.twidda.Backend;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
@ -26,10 +27,14 @@ public class ShowStatus extends AsyncTask<Long, Void, Void> {
private TextView username,scrName, tweet; private TextView username,scrName, tweet;
private ArrayList<twitter4j.Status> answers; private ArrayList<twitter4j.Status> answers;
private String usernameStr, scrNameStr, tweetStr; private String usernameStr, scrNameStr, tweetStr;
private SharedPreferences settings;
private int load;
public ShowStatus( Context c) { public ShowStatus(Context c) {
twitter = TwitterResource.getInstance(c).getTwitter(); twitter = TwitterResource.getInstance(c).getTwitter();
answers = new ArrayList<>(); answers = new ArrayList<>();
settings = c.getSharedPreferences("settings", 0);
load = settings.getInt("preload", 10);
this.c=c; this.c=c;
} }
@ -53,8 +58,8 @@ public class ShowStatus extends AsyncTask<Long, Void, Void> {
usernameStr = currentTweet.getUser().getName(); usernameStr = currentTweet.getUser().getName();
scrNameStr = currentTweet.getUser().getScreenName(); scrNameStr = currentTweet.getUser().getScreenName();
Query query = new Query('@'+scrNameStr+" since_id:"+tweetID); Query query = new Query('@'+scrNameStr+" since_id:"+tweetID+" +exclude:retweets");
query.setCount(10);//TODO query.setCount(load);
QueryResult result= null; QueryResult result= null;
do { do {
result = twitter.search(query); result = twitter.search(query);

View File

@ -64,7 +64,7 @@ public class TwitterResource {
* @throws NullPointerException if Request-Token is not set * @throws NullPointerException if Request-Token is not set
* @see #initKeys(String, String) * @see #initKeys(String, String)
*/ */
public void initialize(String twitterPin) throws TwitterException, NullPointerException{ public void initialize(String twitterPin) throws TwitterException, NullPointerException {
if(reqToken == null) throw new NullPointerException("empty request token"); if(reqToken == null) throw new NullPointerException("empty request token");
AccessToken accessToken = twitter.getOAuthAccessToken(reqToken,twitterPin); AccessToken accessToken = twitter.getOAuthAccessToken(reqToken,twitterPin);
String key1 = accessToken.getToken(); String key1 = accessToken.getToken();
@ -109,7 +109,7 @@ public class TwitterResource {
* get Twitter object * get Twitter object
* @return Twitter Object * @return Twitter Object
*/ */
public Twitter getTwitter(){ public Twitter getTwitter() {
init(); init();
return twitter; return twitter;
} }
@ -119,7 +119,7 @@ public class TwitterResource {
* recall Keys from Shared-Preferences * recall Keys from Shared-Preferences
* & initialize Twitter * & initialize Twitter
*/ */
public void init(){ public void init() {
String key1,key2; String key1,key2;
if( settings.getBoolean("login", false) ) { if( settings.getBoolean("login", false) ) {
key1 = settings.getString("key1", " "); key1 = settings.getString("key1", " ");
@ -135,7 +135,7 @@ public class TwitterResource {
* @return TwitterResource Instance * @return TwitterResource Instance
*/ */
public static TwitterResource getInstance(Context context) { public static TwitterResource getInstance(Context context) {
if(mTwitter == null){ if(mTwitter == null) {
mTwitter = new TwitterResource(context); mTwitter = new TwitterResource(context);
} }
return mTwitter; return mTwitter;

View File

@ -8,20 +8,20 @@ import org.nuclearfog.twidda.R;
public class AppDatabase extends SQLiteOpenHelper public class AppDatabase extends SQLiteOpenHelper
{ {
private static AppDatabase mData; private static AppDatabase mData;
private Context c; private Context context;
private AppDatabase(Context context) { private AppDatabase(Context context) {
super(context, context.getString(R.string.database),null, 1); super(context, context.getString(R.string.database),null, 1);
c = context; context = context;
} }
@Override @Override
public void onCreate(SQLiteDatabase db) { public void onCreate(SQLiteDatabase db) {
String uQuery = c.getString(R.string.tableUser); String uQuery = context.getString(R.string.tableUser);
String tQuery = c.getString(R.string.tableTweet); String tQuery = context.getString(R.string.tableTweet);
String trQuery = c.getString(R.string.tableTrend); String trQuery = context.getString(R.string.tableTrend);
String hQuery = c.getString(R.string.tableHome); String hQuery = context.getString(R.string.tableHome);
String fQuery = c.getString(R.string.tableFavorit); String fQuery = context.getString(R.string.tableFavorit);
db.execSQL(uQuery); db.execSQL(uQuery);
db.execSQL(tQuery); db.execSQL(tQuery);
db.execSQL(trQuery); db.execSQL(trQuery);

View File

@ -24,13 +24,13 @@ public class TrendDatabase {
public TrendDatabase(Trends trends, Context c) { public TrendDatabase(Trends trends, Context c) {
this.trends = trends; this.trends = trends;
this.c=c; this.c = c;
init(); init();
setup(); setup();
store(); store();
} }
public TrendDatabase(Context c){ public TrendDatabase(Context c) {
this.c = c; this.c = c;
init(); init();
load(); load();
@ -47,7 +47,7 @@ public class TrendDatabase {
return size; return size;
} }
private void load(){ private void load() {
SQLiteDatabase db = dataHelper.getReadableDatabase(); SQLiteDatabase db = dataHelper.getReadableDatabase();
String SQL_TREND = "SELECT * FROM trend ORDER BY trendpos ASC"; String SQL_TREND = "SELECT * FROM trend ORDER BY trendpos ASC";
Cursor cursor = db.rawQuery(SQL_TREND,null); Cursor cursor = db.rawQuery(SQL_TREND,null);
@ -66,7 +66,7 @@ public class TrendDatabase {
db.close(); db.close();
} }
private void store(){ private void store() {
SQLiteDatabase db = dataHelper.getWritableDatabase(); SQLiteDatabase db = dataHelper.getWritableDatabase();
ContentValues trend = new ContentValues(); ContentValues trend = new ContentValues();
for(int pos = 0; pos < getSize(); pos++) { for(int pos = 0; pos < getSize(); pos++) {
@ -77,7 +77,7 @@ public class TrendDatabase {
} }
} }
private void init(){ private void init() {
dataHelper = AppDatabase.getInstance(c); dataHelper = AppDatabase.getInstance(c);
trendpos = new ArrayList<>(); trendpos = new ArrayList<>();
trendName = new ArrayList<>(); trendName = new ArrayList<>();

View File

@ -6,19 +6,20 @@ import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
import twitter4j.Status; import twitter4j.Status;
import twitter4j.User; import twitter4j.User;
public class TweetDatabase { public class TweetDatabase {
public static final int HOME_TL = 0; public static final int HOME_TL = 0; // GET HOME TIMELINE
public static final int FAV_TL = 1; public static final int FAV_TL = 1; // GET FAVORITE TL
public static final int USER_TL = 2; public static final int USER_TL = 2; // GET USERS TWEET TL @userID
public static final int GET_TWEET = 3; public static final int GET_TWEET = 3; // GET TWEET @ userID
public static final int GET_MENT = 4; public static final int GET_MENT = 4; // GET MENTION TL
public static final int SEARCH = 5;
private AppDatabase dataHelper; private AppDatabase dataHelper;
private List<String> user,scrname, tweet,pbLink; private List<String> user,scrname, tweet,pbLink;
@ -62,7 +63,6 @@ public class TweetDatabase {
} }
/** /**
* TODO
* this Constructor is used by twitter search * this Constructor is used by twitter search
* no need to store in SQLITE * no need to store in SQLITE
* @param stats Search Result Tweets * @param stats Search Result Tweets
@ -113,11 +113,9 @@ public class TweetDatabase {
if(mode!=USER_TL) { if(mode!=USER_TL) {
if(mode == HOME_TL) { if(mode == HOME_TL) {
db.insertWithOnConflict("timeline",null,home,SQLiteDatabase.CONFLICT_IGNORE); db.insertWithOnConflict("timeline",null,home,SQLiteDatabase.CONFLICT_IGNORE);
} } else if(mode == FAV_TL) {
else if(mode == FAV_TL) {
db.insertWithOnConflict("favorit",null,fav,SQLiteDatabase.CONFLICT_IGNORE); db.insertWithOnConflict("favorit",null,fav,SQLiteDatabase.CONFLICT_IGNORE);
} } else if(mode == GET_MENT) {
else if(mode == GET_MENT) {
db.insertWithOnConflict("timeline",null,ment,SQLiteDatabase.CONFLICT_IGNORE); db.insertWithOnConflict("timeline",null,ment,SQLiteDatabase.CONFLICT_IGNORE);
} }
} }
@ -215,6 +213,11 @@ public class TweetDatabase {
long days = hours / 24; long days = hours / 24;
long weeks = days / 7; long weeks = days / 7;
if(weeks > 4) {
Date tweetDate = new Date(mills);
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
return sdf.format(tweetDate);
}
if(weeks > 0) if(weeks > 0)
return "vor "+weeks+" w"; return "vor "+weeks+" w";
if(days > 0) if(days > 0)

View File

@ -191,7 +191,7 @@ public class MainActivity extends AppCompatActivity
} }
/** /**
* Swipe To Refresh Listener TODO * Swipe To Refresh Listener
*/ */
private void setRefreshListener() { private void setRefreshListener() {
timelineReload.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { timelineReload.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@ -217,9 +217,8 @@ public class MainActivity extends AppCompatActivity
}); });
} }
/** /**
* Item Listener for a TweetDetail * Set On Item Click Listener for the main Listviews
*/ */
private void setListViewListener() { private void setListViewListener() {
timelineList.setOnItemClickListener(new AdapterView.OnItemClickListener() { timelineList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@ -242,8 +241,8 @@ public class MainActivity extends AppCompatActivity
trendList.setOnItemClickListener(new AdapterView.OnItemClickListener() { trendList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TrendDatabase trend = ((TrendDatabase) trendList.getAdapter()); TrendAdapter trend = (TrendAdapter) trendList.getAdapter();
String search = trend.getTrendname(position); String search = trend.getDatabase().getTrendname(position);
Intent intent = new Intent(con, TwitterSearch.class); Intent intent = new Intent(con, TwitterSearch.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("search", search); bundle.putString("search", search);
@ -255,10 +254,10 @@ public class MainActivity extends AppCompatActivity
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(!mentionReload.isRefreshing()) { if(!mentionReload.isRefreshing()) {
TweetDatabase tweetDeck = new TweetDatabase(con,TweetDatabase.GET_MENT, 0L); TimelineAdapter tlAdp = (TimelineAdapter) timelineList.getAdapter();
int index = mentionList.getPositionForView(view); TweetDatabase twDB = tlAdp.getAdapter();
long tweetID = tweetDeck.getTweetId(index); long tweetID = twDB.getTweetId(position);
long userID = tweetDeck.getUserID(index); long userID = twDB.getUserID(position);
Intent intent = new Intent(con, TweetDetail.class); Intent intent = new Intent(con, TweetDetail.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID); bundle.putLong("tweetID",tweetID);

View File

@ -24,7 +24,7 @@ public class TimelineAdapter extends ArrayAdapter {
this.context = context; this.context = context;
} }
public TweetDatabase getAdapter(){ public TweetDatabase getAdapter() {
return mTweets; return mTweets;
} }

View File

@ -20,6 +20,10 @@ public class TrendAdapter extends ArrayAdapter {
this.context = context; this.context = context;
} }
public TrendDatabase getDatabase(){
return trend;
}
@Override @Override
public int getCount() { public int getCount() {
return trend.getSize(); return trend.getSize();

View File

@ -1,6 +1,7 @@
package org.nuclearfog.twidda.Window; package org.nuclearfog.twidda.Window;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -10,40 +11,43 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.NumberPicker;
import android.widget.Switch; import android.widget.Switch;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
public class AppSettings extends AppCompatActivity { public class AppSettings extends AppCompatActivity {
private Button delButon;
private Switch toggleImg;
private EditText woeId;
private SharedPreferences settings; private SharedPreferences settings;
private NumberPicker load_factor;
private Editor edit;
@Override @Override
protected void onCreate(Bundle savedInst) { protected void onCreate(Bundle savedInst) {
super.onCreate(savedInst); super.onCreate(savedInst);
settings = getApplicationContext().getSharedPreferences("settings", 0);
setContentView(R.layout.settings); setContentView(R.layout.settings);
Toolbar tool = (Toolbar) findViewById(R.id.toolbar_setting);
setSupportActionBar(tool);
Switch toggleImg = (Switch) findViewById(R.id.toggleImg); settings = getApplicationContext().getSharedPreferences("settings", 0);
int location = settings.getInt("woeid",23424829);
edit = settings.edit();
Toolbar tool = (Toolbar) findViewById(R.id.toolbar_setting);
load_factor = (NumberPicker)findViewById(R.id.tweet_load);
delButon = (Button) findViewById(R.id.delete_db);
toggleImg = (Switch) findViewById(R.id.toggleImg);
woeId = (EditText) findViewById(R.id.woeid);
setSupportActionBar(tool);
load_factor.setMinValue(5);
load_factor.setMaxValue(100);
toggleImg.setChecked(settings.getBoolean("image_load",false)); toggleImg.setChecked(settings.getBoolean("image_load",false));
toggleImg.setOnCheckedChangeListener( woeId.setText(""+location);
new CompoundButton.OnCheckedChangeListener() {
@Override setListener();
public void onCheckedChanged(CompoundButton b, boolean checked){
SharedPreferences.Editor e = settings.edit();
e.putBoolean("image_load", checked);
e.apply();
}
});
Button delButon = (Button) findViewById(R.id.delete_db);
delButon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getApplicationContext().deleteDatabase(getApplicationContext().getString(R.string.database));
}
});
} }
/** /**
@ -60,12 +64,42 @@ public class AppSettings extends AppCompatActivity {
*/ */
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) switch(item.getItemId()) {
{
case R.id.back_settings: case R.id.back_settings:
finish(); finish();
break;
}
return true; return true;
} }
return false;
}
@Override
protected void onDestroy() {
edit.putInt("woeid", Integer.valueOf(woeId.getText().toString()));
edit.putInt("preload", load_factor.getValue());
edit.apply();
super.onDestroy();
}
private void setListener() {
toggleImg.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton b, boolean checked) {
edit.putBoolean("image_load", checked);
edit.apply();
}
});
delButon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getApplicationContext().deleteDatabase(getApplicationContext().getString(R.string.database));
}
});
}
} }

View File

@ -1,20 +1,24 @@
package org.nuclearfog.twidda.Window; package org.nuclearfog.twidda.Window;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import org.nuclearfog.twidda.Backend.ShowStatus; import org.nuclearfog.twidda.Backend.ShowStatus;
import org.nuclearfog.twidda.DataBase.TweetDatabase; import org.nuclearfog.twidda.DataBase.TweetDatabase;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.ViewAdapter.TimelineAdapter;
public class TweetDetail extends AppCompatActivity { public class TweetDetail extends AppCompatActivity {
private TweetDatabase mTweet; private ListView answer_list;
private Context context;
private long tweetID; private long tweetID;
private long userID; private long userID;
@ -25,7 +29,7 @@ public class TweetDetail extends AppCompatActivity {
tweetID = getIntent().getExtras().getLong("tweetID"); tweetID = getIntent().getExtras().getLong("tweetID");
userID = getIntent().getExtras().getLong("userID"); userID = getIntent().getExtras().getLong("userID");
answer_list = (ListView) findViewById(R.id.answer_list);
ImageView pb = (ImageView) findViewById(R.id.profileimage_detail); ImageView pb = (ImageView) findViewById(R.id.profileimage_detail);
pb.setOnClickListener(new View.OnClickListener() { pb.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -38,16 +42,35 @@ public class TweetDetail extends AppCompatActivity {
} }
}); });
setContent(); setContent();
setListViewListener();
} }
@Override @Override
protected void onDestroy(){ protected void onDestroy() {
super.onDestroy(); super.onDestroy();
} }
private void setListViewListener() {
context = getApplicationContext();
answer_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TimelineAdapter tlAdp = (TimelineAdapter) answer_list.getAdapter();
TweetDatabase twDB = tlAdp.getAdapter();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
Intent intent = new Intent(context, TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
bundle.putLong("userID",userID);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
private void setContent() { private void setContent() {
ShowStatus set = new ShowStatus(this); ShowStatus set = new ShowStatus(this);
set.execute(tweetID); set.execute(tweetID);
} }
} }

View File

@ -15,7 +15,7 @@ public class TweetPopup extends AppCompatActivity {
private EditText tweetfield; private EditText tweetfield;
@Override @Override
protected void onCreate(Bundle SavedInstance){ protected void onCreate(Bundle SavedInstance) {
super.onCreate(SavedInstance); super.onCreate(SavedInstance);
getWindow().setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); getWindow().setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
setContentView(R.layout.tweetwindow); setContentView(R.layout.tweetwindow);
@ -38,7 +38,7 @@ public class TweetPopup extends AppCompatActivity {
}); });
} }
private void send(){ private void send() {
String tweet = tweetfield.getText().toString(); String tweet = tweetfield.getText().toString();
SendStatus sendTweet = new SendStatus(getApplicationContext()); SendStatus sendTweet = new SendStatus(getApplicationContext());
sendTweet.execute(SendStatus.SEND_STATUS, tweet); sendTweet.execute(SendStatus.SEND_STATUS, tweet);

View File

@ -13,7 +13,9 @@ import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import org.nuclearfog.twidda.Backend.Search; import org.nuclearfog.twidda.Backend.Search;
import org.nuclearfog.twidda.DataBase.TweetDatabase;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.ViewAdapter.TimelineAdapter;
public class TwitterSearch extends AppCompatActivity { public class TwitterSearch extends AppCompatActivity {
@ -61,8 +63,18 @@ public class TwitterSearch extends AppCompatActivity {
searchTL.setOnItemClickListener(new AdapterView.OnItemClickListener() { searchTL.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int index = searchTL.getPositionForView(view); if(!search_refresh.isRefreshing()) {
TimelineAdapter tlAdp = (TimelineAdapter) searchTL.getAdapter();
TweetDatabase twDB = tlAdp.getAdapter();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
Intent intent = new Intent(getApplicationContext(), TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
bundle.putLong("userID",userID);
intent.putExtras(bundle);
startActivity(intent);
}
} }
}); });
} }
@ -71,4 +83,6 @@ public class TwitterSearch extends AppCompatActivity {
Search s = new Search(this); Search s = new Search(this);
s.execute("tweet",search); s.execute("tweet",search);
} }
} }

View File

@ -7,6 +7,8 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TabHost; import android.widget.TabHost;
@ -142,5 +144,43 @@ public class UserProfile extends AppCompatActivity {
mProfile.execute(userId, mode); mProfile.execute(userId, mode);
} }
private void setListener(){} /**
* Set On Item Click Listener
*/
private void setListener(){
homeTweets.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(!homeReload.isRefreshing()) {
TimelineAdapter tlAdp = (TimelineAdapter) homeTweets.getAdapter();
TweetDatabase twDB = tlAdp.getAdapter();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
Intent intent = new Intent(getApplicationContext(), TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
bundle.putLong("userID",userID);
intent.putExtras(bundle);
startActivity(intent);
}
}
});
homeFavorits.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(!favoriteReload.isRefreshing()) {
TimelineAdapter tlAdp = (TimelineAdapter) homeFavorits.getAdapter();
TweetDatabase twDB = tlAdp.getAdapter();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
Intent intent = new Intent(getApplicationContext(), TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
bundle.putLong("userID",userID);
intent.putExtras(bundle);
startActivity(intent);
}
}
});
}
} }

View File

@ -11,22 +11,54 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" /> android:layout_height="?attr/actionBarSize" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="5dp">
<NumberPicker
android:id="@+id/tweet_load"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal"
android:padding="10dp">
<Switch <Switch
android:id="@+id/toggleImg" android:id="@+id/toggleImg"
android:layout_width="180dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content" />
android:layout_margin="20dp" </LinearLayout>
android:text="@string/image" />
<Spinner <LinearLayout
android:id="@+id/location_list" android:layout_width="match_parent"
android:layout_width="180dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="20dp"></Spinner> android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal"
android:padding="10dp">
<EditText
android:id="@+id/woeid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
<Button <Button
android:id="@+id/delete_db" android:id="@+id/delete_db"
android:layout_width="180dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="20dp" android:layout_margin="20dp"
android:background="@android:color/holo_red_dark" android:background="@android:color/holo_red_dark"

View File

@ -20,8 +20,10 @@
<string name="connection_failure">Fehler beim Abruf der Daten!</string> <string name="connection_failure">Fehler beim Abruf der Daten!</string>
<string name="search">Suche</string> <string name="search">Suche</string>
<string name="tweet_image">TwitterBild</string> <string name="tweet_image">TwitterBild</string>
<string name="trend">Trends</string>
<string-array name="countries"> <string-array name="countries">
<item>Deutschland</item> <item>Deutschland</item>
<item>Welt</item>
</string-array> </string-array>
<string name="tableUser"> <string name="tableUser">
@ -70,5 +72,6 @@
trendname TEXT, trendname TEXT,
trendlink TEXT); trendlink TEXT);
</string> </string>
<string name="woe_id">WOE ID</string>
</resources> </resources>