This commit is contained in:
NudeDude 2017-12-30 19:01:49 +01:00
parent 2535a1bc55
commit 5d819cedea
17 changed files with 191 additions and 63 deletions

View File

@ -20,26 +20,31 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Window.Profile"
android:theme="@style/AppTheme"
android:screenOrientation="portrait">
</activity>
android:screenOrientation="portrait"/>
<activity
android:name=".Window.TweetWindow"
android:theme="@style/Transparency"
android:screenOrientation="portrait">
</activity>
android:screenOrientation="portrait"/>
<activity
android:name=".Window.Settings"
android:theme="@style/AppTheme"
android:screenOrientation="portrait">
</activity>
android:screenOrientation="portrait"/>
<activity
android:name=".Window.Tweet"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"/>
<activity
android:name=".Window.TwitterSearch"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"/>
</application>
</manifest>

View File

@ -11,7 +11,7 @@ public class AppDatabase extends SQLiteOpenHelper
private Context c;
private AppDatabase(Context context) {
super(context, "twitter.sqlite",null, 1);
super(context, context.getString(R.string.database),null, 1);
c = context;
}

View File

@ -17,14 +17,15 @@ public class TweetDatabase {
public static final int FAV_TL = 1;
public static final int USER_TL = 2;
public static final int GET_TWEET = 3;
public static final int GET_MENT = 4;
private AppDatabase dataHelper;
private List<String> user,tweet,noRT,noFav,noAns,pbLink;
private List<String> user,scrname, tweet,noRT,noFav,noAns,pbLink;
private List<Long> userId,tweetId,timeMillis;
private List<Status> stats;
private int size = 0;
private int mode = 0;
private int length = 50;
private int limit;
private long CurrentId = 0;
private SharedPreferences settings;
@ -40,9 +41,7 @@ public class TweetDatabase {
this.stats=stats;
this.CurrentId = CurrentId;
this.mode=mode;
dataHelper = AppDatabase.getInstance(context);
settings = context.getSharedPreferences("settings", 0);
initArray();
initialize(context);
store();
load();
}
@ -56,9 +55,7 @@ public class TweetDatabase {
public TweetDatabase(Context context, final int mode, long CurrentId) {
this.CurrentId=CurrentId;
this.mode=mode;
dataHelper = AppDatabase.getInstance(context);
settings = context.getSharedPreferences("settings", 0);
initArray();
initialize(context);
load();
}
@ -68,6 +65,7 @@ public class TweetDatabase {
ContentValues tweet = new ContentValues();
ContentValues home = new ContentValues();
ContentValues fav = new ContentValues();
ContentValues ment = new ContentValues();
for(int pos = 0; pos < stats.size(); pos++) {
Status stat = stats.get(pos);
@ -75,6 +73,7 @@ public class TweetDatabase {
user.put("userID",usr.getId());
user.put("username", usr.getName());
user.put("scrname",'@'+usr.getScreenName());
user.put("pbLink", usr.getProfileImageURL());
user.put("banner", usr.getProfileBannerURL());
user.put("bio",usr.getDescription());
@ -93,6 +92,8 @@ public class TweetDatabase {
fav.put("tweetID", stat.getId());
fav.put("ownerID", CurrentId);
ment.put("mTweetID",stat.getId());
db.insertWithOnConflict("user",null, user,SQLiteDatabase.CONFLICT_IGNORE);
db.insertWithOnConflict("tweet",null, tweet,SQLiteDatabase.CONFLICT_IGNORE);
@ -103,6 +104,9 @@ public class TweetDatabase {
else if(mode == FAV_TL) {
db.insertWithOnConflict("favorit",null,fav,SQLiteDatabase.CONFLICT_IGNORE);
}
else if(mode == GET_MENT) {
db.insertWithOnConflict("timeline",null,ment,SQLiteDatabase.CONFLICT_IGNORE);
}
}
}
db.close();
@ -129,6 +133,10 @@ public class TweetDatabase {
} else if(mode==GET_TWEET) {
SQL_GET_HOME = "SELECT * FROM user INNER JOIN tweet ON user.userID = tweet.userID " +
"WHERE tweet.tweetID = "+CurrentId+" ORDER BY tweet.time DESC";
} else if(mode==GET_MENT){
SQL_GET_HOME = "SELECT * FROM timeline " +
"INNER JOIN tweet ON timeline.mTweetID = tweet.tweetID " +
"INNER JOIN user ON tweet.userID=user.userID ORDER BY time DESC";
}
Cursor cursor = db.rawQuery(SQL_GET_HOME,null);
@ -147,6 +155,8 @@ public class TweetDatabase {
noAns.add(cursor.getString(index));
index = cursor.getColumnIndex("username"); // user
user.add(cursor.getString(index) );
index = cursor.getColumnIndex("scrname"); // username
scrname.add(cursor.getString(index) );
index = cursor.getColumnIndex("pbLink"); // image
pbLink.add(cursor.getString(index) );
index = cursor.getColumnIndex("userID"); // UserID
@ -154,7 +164,7 @@ public class TweetDatabase {
index = cursor.getColumnIndex("tweetID"); // tweetID
tweetId.add(cursor.getLong(index) );
size++;
} while(cursor.moveToNext() && size < length);
} while(cursor.moveToNext() && size < limit);
}
cursor.close();
db.close();
@ -167,6 +177,7 @@ public class TweetDatabase {
public long getTweetId(int pos){return tweetId.get(pos);}
public long getTime(int pos){return timeMillis.get(pos);}
public String getUsername(int pos){return user.get(pos);}
public String getScreenname(int pos){return scrname.get(pos);}
public String getTweet(int pos){return tweet.get(pos);}
public String getRetweet(int pos){return noRT.get(pos);}
public String getFavorite(int pos){return noFav.get(pos);}
@ -203,8 +214,16 @@ public class TweetDatabase {
return "vor "+seconds+" s";
}
private void initialize(Context c){
dataHelper = AppDatabase.getInstance(c);
settings = c.getSharedPreferences("settings", 0);
limit = settings.getInt("limit", 50);
initArray();
}
private void initArray() {
user = new ArrayList<>();
scrname = new ArrayList<>();
tweet = new ArrayList<>();
noRT = new ArrayList<>();
noFav = new ArrayList<>();

View File

@ -57,11 +57,11 @@ public class ProfileTweets extends AsyncTask<Long, Void, Void> {
protected void onPostExecute(Void v) {
if(homeTl != null){
profileTweets.setAdapter(homeTl);
tweetsReload.setRefreshing(false);
}
else if(homeFav != null){
profileFavorits.setAdapter(homeFav);
favoritsReload.setRefreshing(false);
}
tweetsReload.setRefreshing(false);
favoritsReload.setRefreshing(false);
}
}

View File

@ -15,6 +15,12 @@ public class RegisterAccount extends AsyncTask<String, Void, String>
private Button verifierButton, loginButton;
private Context context;
/**
* Register App for Account access
* @see MainActivity
* @see TwitterStore used to Store Twitter instance
* @param context current Activity's Context.
*/
public RegisterAccount( Context context ){
this.context = context;
}
@ -46,10 +52,10 @@ public class RegisterAccount extends AsyncTask<String, Void, String>
@Override
protected void onPostExecute(String msg) {
if( msg=="success" ) {
if( msg.equals("success") ) {
verifierButton.setVisibility(Button.INVISIBLE);
loginButton.setVisibility(Button.VISIBLE);
loginButton.setBackgroundColor(0xFFFF0000);//todo
loginButton.setBackgroundColor(0xFFFF0000);
} else if( !msg.trim().isEmpty() ) {
Toast.makeText(context,"Fehler: "+msg,Toast.LENGTH_LONG).show();
}

View File

@ -16,18 +16,21 @@ import android.os.AsyncTask;
import twitter4j.Twitter;
import twitter4j.TwitterException;
public class TwitterEngine extends AsyncTask<Integer, Void, Void>
public class TwitterEngine extends AsyncTask<Integer, Void, Boolean>
{
private final String ERR_MSG = "Fehler bei der Verbindung";
private TwitterStore twitterStore;
private Context context;
private SwipeRefreshLayout timelineRefresh, trendRefresh, mentionRefresh;
private ListView timelineList, trendList, mentionList;
private TimelineAdapter timelineAdapter;
private TimelineAdapter timelineAdapter, mentionAdapter;
private TrendsAdapter trendsAdapter;
/**
* Main View
* @see MainActivity
*/
public TwitterEngine(Context context) {
this.context=context;
twitterStore = TwitterStore.getInstance(context);
@ -49,10 +52,10 @@ public class TwitterEngine extends AsyncTask<Integer, Void, Void>
/**
* @param args [0] Executing Mode: (0)HomeTL, (1)Trend, (2)Mention
*
* @return success
*/
@Override
protected Void doInBackground(Integer... args) {
protected Boolean doInBackground(Integer... args) {
Twitter twitter = twitterStore.getTwitter();
try {
if(args[0]==0) {
@ -63,24 +66,31 @@ public class TwitterEngine extends AsyncTask<Integer, Void, Void>
TrendDatabase trend = new TrendDatabase(twitter.getPlaceTrends(23424829),context); //Germany by default
trendsAdapter = new TrendsAdapter(context,trend);
}
else if(args[0]==2) { //TODO
// twitter.getMentionsTimeline()
else if(args[0]==2) {
TweetDatabase mention = new TweetDatabase(twitter.getMentionsTimeline(), context,TweetDatabase.GET_MENT,0);
mentionAdapter = new TimelineAdapter(context,mention);
}
} catch (TwitterException e) {
Toast.makeText(context, ERR_MSG, Toast.LENGTH_LONG).show();
} catch (Exception e){ e.printStackTrace(); }
return null;
return false;
} catch (Exception e){
e.printStackTrace();
return false;
}
return true;
}
/**
* Refresh List in a new Thread
*/
@Override
protected void onPostExecute(Void v) {
if(timelineAdapter != null)
timelineList.setAdapter(timelineAdapter);
else if(trendsAdapter != null)
trendList.setAdapter(trendsAdapter);
protected void onPostExecute(Boolean success) {
if(success) {
if(timelineAdapter != null)
timelineList.setAdapter(timelineAdapter);
else if(trendsAdapter != null)
trendList.setAdapter(trendsAdapter);
else if(mentionAdapter != null)
mentionList.setAdapter(mentionAdapter);
} else {
Toast.makeText(context, context.getString(R.string.connection_failure), Toast.LENGTH_LONG).show();
}
if(timelineRefresh.isRefreshing())
timelineRefresh.setRefreshing(false);
else if(mentionRefresh.isRefreshing())

View File

@ -241,13 +241,25 @@ public class MainActivity extends AppCompatActivity
trendList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.out.println("1 klick: "+position); //TODO
TrendDatabase trend = new TrendDatabase(con);
trend.getTrendname(position);
}
});
mentionList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.out.println("2 klick"+position); //TODO
if(!mentionReload.isRefreshing()) {
TweetDatabase tweetDeck = new TweetDatabase(con,TweetDatabase.GET_MENT, 0L);
int index = mentionList.getPositionForView(view);
long tweetID = tweetDeck.getTweetId(index);
long userID = tweetDeck.getUserID(index);
Intent intent = new Intent(con, Tweet.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
bundle.putLong("userID",userID);
intent.putExtras(bundle);
startActivity(intent);
}
}
});
}

View File

@ -37,6 +37,7 @@ public class TimelineAdapter extends ArrayAdapter {
v = inf.inflate(R.layout.tweet, parent,false);
}
((TextView) v.findViewById(R.id.username)).setText(mTweets.getUsername(position));
((TextView) v.findViewById(R.id.screenname)).setText(mTweets.getScreenname(position));
((TextView) v.findViewById(R.id.tweettext)).setText(mTweets.getTweet(position));
((TextView) v.findViewById(R.id.answer_number)).setText(mTweets.getAnswer(position));
((TextView) v.findViewById(R.id.retweet_number)).setText(mTweets.getRetweet(position));

View File

@ -20,6 +20,7 @@ import org.nuclearfog.twidda.ViewAdapter.TimelineAdapter;
public class Profile extends AppCompatActivity {
private SwipeRefreshLayout homeReload, favoriteReload;
private ListView homeTweets, homeFavorits;
private long userId;
@ -64,7 +65,6 @@ public class Profile extends AppCompatActivity {
return true;
}
/**
* Init Tab Listener
*/
@ -84,7 +84,10 @@ public class Profile extends AppCompatActivity {
// Listener
mTab.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) { }
public void onTabChanged(String tabId) {
homeReload.setRefreshing(false);
favoriteReload.setRefreshing(false);
}
});
}
@ -92,15 +95,15 @@ public class Profile extends AppCompatActivity {
* Init SwipeRefresh
*/
private void initSwipe(){
SwipeRefreshLayout homeReload = (SwipeRefreshLayout) findViewById(R.id.hometweets);
homeReload = (SwipeRefreshLayout) findViewById(R.id.hometweets);
homeReload.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
getTweets(0L);
}
});
SwipeRefreshLayout favoritReload = (SwipeRefreshLayout) findViewById(R.id.homefavorits);
favoritReload.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
favoriteReload = (SwipeRefreshLayout) findViewById(R.id.homefavorits);
favoriteReload.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
getTweets(1L);

View File

@ -6,6 +6,8 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Switch;
@ -35,8 +37,13 @@ public class Settings extends AppCompatActivity {
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));
}
});
}
/**

View File

@ -28,24 +28,24 @@ public class Tweet extends AppCompatActivity {
ImageView pb = (ImageView) findViewById(R.id.profileimage_detail);
pb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent profile = new Intent(getApplicationContext(), Profile.class);
Bundle bundle = new Bundle();
bundle.putLong("userID",userID);
profile.putExtras(bundle);
startActivity(profile);
}
});
@Override
public void onClick(View v) {
Intent profile = new Intent(getApplicationContext(), Profile.class);
Bundle bundle = new Bundle();
bundle.putLong("userID",userID);
profile.putExtras(bundle);
startActivity(profile);
}
});
setContent();
}
private void setContent() {
mTweet = new TweetDatabase(getApplicationContext(),TweetDatabase.GET_TWEET,tweetID);
String scrName = mTweet.getUsername(0)+" "+mTweet.getScreenname(0);
tweet.setText(mTweet.getTweet(0));
username.setText(mTweet.getUsername(0));
username.setText(scrName);
}
}

View File

@ -0,0 +1,20 @@
package org.nuclearfog.twidda.Window;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class TwitterSearch extends AppCompatActivity {
private String keyWord;
@Override
protected void onCreate(Bundle bundle){
super.onCreate(bundle);
keyWord = getIntent().getExtras().getString("search");
}
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>

View File

@ -15,11 +15,21 @@
android:id="@+id/toggleImg"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="@string/image" />
<Spinner
android:id="@+id/location_list"
android:layout_width="180dp"
android:layout_height="wrap_content"></Spinner>
android:layout_height="wrap_content"
android:layout_margin="20dp"></Spinner>
<Button
android:id="@+id/delete_db"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="@android:color/holo_red_dark"
android:text="@string/delete_database" />
</LinearLayout>

View File

@ -19,6 +19,11 @@
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<TextView
android:id="@+id/screenname"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<TextView
android:id="@+id/time"
android:layout_width="fill_parent"

View File

@ -8,6 +8,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<ImageView
@ -42,12 +43,25 @@
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp" />
android:layout_marginTop="5dp"
android:autoLink="web"
android:linksClickable="true"
android:textSize="24sp" />
<ImageView
android:id="@+id/tweet_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:contentDescription="@string/tweet_image"
android:visibility="invisible"
app:srcCompat="@android:color/darker_gray" />
<LinearLayout
android:id="@+id/actionbar"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_margin="5dp"
android:addStatesFromChildren="false"
android:gravity="right"
android:orientation="horizontal">

View File

@ -14,14 +14,16 @@
<string name="tweet">Tweet</string>
<string name="settings">Einstellungen</string>
<string name="back">Back</string>
<string name="datei">timeline.db</string>
<string name="database">database.db</string>
<string name="image">Bilder Laden</string>
<string name="delete_database">Datenbank Löschen</string>
<string name="connection_failure">Fehler beim Abruf der Daten!</string>
<string name="tableUser">
CREATE TABLE IF NOT EXISTS user (
userID INTEGER PRIMARY KEY,
username TEXT,
scrname TEXT,
pbLink TEXT,
banner TEXT,
bio TEXT,
@ -52,7 +54,9 @@
<string name="tableHome">
CREATE TABLE IF NOT EXISTS timeline (
tweetID INTEGER UNIQUE,
FOREIGN KEY (tweetID) REFERENCES tweet(tweetID));
mTweetID INTEGER UNIQUE,
FOREIGN KEY (tweetID) REFERENCES tweet(tweetID));
FOREIGN KEY (mTweetID) REFERENCES tweet(tweetID));
</string>
<string name="tableTrend">
@ -61,4 +65,10 @@
trendname TEXT,
trendlink TEXT);
</string>
<string name="tweet_image">TwitterBild</string>
<string-array name="countries">
<item>Deutschland</item>
</string-array>
</resources>