This commit is contained in:
Sufian 2018-05-22 18:53:51 +02:00
parent fb71d5e1a0
commit 2ecbd756af
16 changed files with 81 additions and 58 deletions

View File

@ -13,8 +13,9 @@ android {
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

View File

@ -7,7 +7,6 @@ import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
@ -74,7 +73,6 @@ public class ImagePopup extends AsyncTask<String, Void, Boolean> {
}
return true;
} catch (Exception err) {
Log.e("shitter:","Image download failed!");
err.printStackTrace();
ErrorLog errorLog = new ErrorLog(ui.get());
errorLog.add(err.getMessage());

View File

@ -99,7 +99,9 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
} else {
tweet = mTwitter.getStatus(tweetID);
if(MODE == LOAD_TWEET) {
new DatabaseAdapter(ui.get()).storeStatus(tweet);
DatabaseAdapter dbAdp = new DatabaseAdapter(ui.get());
if(dbAdp.containStatus(tweetID))
dbAdp.storeStatus(tweet);
}
}
@ -155,7 +157,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
}
else if(MODE == LOAD_REPLY) {
List<Tweet> answers;
DatabaseAdapter twdb = new DatabaseAdapter(ui.get());
DatabaseAdapter mData = new DatabaseAdapter(ui.get());
String replyname = tweet.user.screenname;
if(tlAdp.getItemCount() > 0) {
long sinceId = tlAdp.getItemId(0);
@ -166,7 +168,8 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
}
tlAdp.setData(answers);
tlAdp.setColor(highlight, font);
twdb.store(answers,DatabaseAdapter.TWEET,-1L);
if(mData.containStatus(tweetID))
mData.store(answers,DatabaseAdapter.TWEET,-1L);
}
else if(MODE == DELETE) {
mTwitter.deleteTweet(tweetID);

View File

@ -38,7 +38,7 @@ import twitter4j.conf.ConfigurationBuilder;
public class TwitterEngine {
private final String TWITTER_CONSUMER_KEY = "0EKRHWYcakpCkl8Lr4OcBFMZb";
private final String TWITTER_CONSUMER_SECRET = "GET YOUR OWN KEY";
private final String TWITTER_CONSUMER_SECRET = "RQrf0uQus5v7IMuYgdlVeBuLw1ApRJhxcAMM8MyUVRh1nKSxnR";
private static TwitterEngine mTwitter;
private static long twitterID = -1L;
@ -149,7 +149,7 @@ public class TwitterEngine {
* set amount of tweets to be loaded
*/
private void setLoad() {
load = settings.getInt("preload", 10);
load = settings.getInt("preload", 20);
}
/**

View File

@ -180,6 +180,36 @@ public class DatabaseAdapter {
}
/**
* Delete Status
* @param id Status id
*/
public void removeStatus(final long id) {
new Thread(new Runnable() {
@Override
public void run() {
SQLiteDatabase db = dataHelper.getWritableDatabase();
db.delete("tweet", "tweetID="+id, null);
}
}).start();
}
/**
* Check if Tweet exists in Database
* @param id Tweet ID
* @return true if found
*/
public boolean containStatus(long id) {
SQLiteDatabase db = dataHelper.getReadableDatabase();
String query = "SELECT EXISTS(SELECT tweetID FROM tweet WHERE tweetID="+id+" LIMIT 1);";
Cursor c = db.rawQuery(query,null);
c.moveToFirst();
boolean found = c.getInt(0) == 1;
c.close();
return found;
}
private Tweet getStatus(Cursor cursor) {
int index;
index = cursor.getColumnIndex("time");
@ -289,15 +319,4 @@ public class DatabaseAdapter {
userColumn.put("follower", user.follower);
db.insertWithOnConflict("user",null, userColumn,SQLiteDatabase.CONFLICT_REPLACE);
}
public void removeStatus(final long id) {
new Thread(new Runnable() {
@Override
public void run() {
SQLiteDatabase db = dataHelper.getWritableDatabase();
db.delete("tweet", "tweetID="+id, null);
}
}).start();
}
}

View File

@ -22,7 +22,6 @@ public class LogAdapter extends RecyclerView.Adapter<LogAdapter.ItemHolder> {
@Override
public int getItemCount(){return messages.size();}
@NonNull
@Override
public LogAdapter.ItemHolder onCreateViewHolder(@NonNull ViewGroup parent, int index) {
@ -36,7 +35,6 @@ public class LogAdapter extends RecyclerView.Adapter<LogAdapter.ItemHolder> {
vh.message.setTextColor(0xffff0000);
}
class ItemHolder extends RecyclerView.ViewHolder {
public final TextView message;
ItemHolder(View v) {
@ -44,5 +42,4 @@ public class LogAdapter extends RecyclerView.Adapter<LogAdapter.ItemHolder> {
message = v.findViewById(R.id.errortext);
}
}
}

View File

@ -138,7 +138,7 @@ public class AppSettings extends AppCompatActivity implements View.OnClickListen
case R.id.error_call:
List<String> messages = new ErrorLog(this).getErrorList();
LogAdapter adp = new LogAdapter(messages);
View list = LayoutInflater.from(this).inflate(R.layout.errorpage,null,false);
View list = LayoutInflater.from(this).inflate(R.layout.errorpage,null);
RecyclerView loglist = list.findViewById(R.id.log_list);
loglist.setLayoutManager(new LinearLayoutManager(this));
loglist.setAdapter(adp);
@ -244,9 +244,8 @@ public class AppSettings extends AppCompatActivity implements View.OnClickListen
}
private void loadSettings() {
settings = getSharedPreferences("settings", 0);
clip = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
row = settings.getInt("preload",10);
row = settings.getInt("preload",20);
wId = settings.getInt("woeid",23424829);
imgEnabled = settings.getBoolean("image_load",true);

View File

@ -34,6 +34,8 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
private RecyclerView tweetSearch,userSearch;
private SwipeRefreshLayout tweetReload;
private TwitterSearch mSearch;
private TabHost tabhost;
private String currenttab = "search_result";
private String search = "";
@Override
@ -57,7 +59,7 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
setSupportActionBar(tool);
if(getSupportActionBar() != null)
getSupportActionBar().setDisplayShowTitleEnabled(false);
TabHost tabhost = findViewById(R.id.search_tab);
tabhost = findViewById(R.id.search_tab);
tabhost.setup();
setTabs(tabhost);
@ -66,6 +68,17 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
getContent();
}
@Override
public void onBackPressed() {
if(currenttab.equals("user_result")) {
tabhost.setCurrentTab(0);
}
else {
super.onBackPressed();
}
}
@Override
protected void onDestroy() {
mSearch.cancel(true);
@ -165,8 +178,10 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
@Override
public void onTabChanged(String tabId) {
if(tabId.equals("user_result"))
currenttab = tabId;
if(tabId.equals("user_result")) {
tweetReload.setRefreshing(false);
}
}
private void setTabs(TabHost tabhost) {

View File

@ -55,7 +55,7 @@ public class UserDetail extends AppCompatActivity implements UserRecycler.OnItem
* Home Button
*/
@Override
protected void onUserLeaveHint(){
protected void onUserLeaveHint() {
super.onUserLeaveHint();
overridePendingTransition(0,0);
}

View File

@ -35,6 +35,7 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
private SwipeRefreshLayout homeReload, favoriteReload;
private RecyclerView homeList, favoritList;
private long userId;
private TabHost mTab;
private boolean home;
private String username = "";
private String currentTab = "tweets";
@ -73,8 +74,8 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
TextView txtFollowing = findViewById(R.id.following);
TextView txtFollower = findViewById(R.id.follower);
TabHost mTab = findViewById(R.id.profile_tab);
setTabs(mTab);
mTab = findViewById(R.id.profile_tab);
setTabs();
mTab.setOnTabChangedListener(this);
txtFollowing.setOnClickListener(this);
txtFollower.setOnClickListener(this);
@ -85,12 +86,11 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
@Override
public void onBackPressed() {
mProfile.cancel(true);
if(mTweets != null)
mTweets.cancel(true);
if(mFavorits != null)
mFavorits.cancel(true);
super.onBackPressed();
if(currentTab.equals("tweets")) {
super.onBackPressed();
} else {
mTab.setCurrentTab(0);
}
}
/**
@ -102,6 +102,16 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
overridePendingTransition(0,0);
}
@Override
protected void onDestroy() {
mProfile.cancel(true);
if(mTweets != null)
mTweets.cancel(true);
if(mFavorits != null)
mFavorits.cancel(true);
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu m) {
getMenuInflater().inflate(R.menu.profile, m);
@ -194,7 +204,7 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
}
private void setTabs(TabHost mTab) {
private void setTabs() {
mTab.setup();
TabHost.TabSpec tab1 = mTab.newTabSpec("tweets");
tab1.setContent(R.id.hometweets);

View File

@ -1,4 +0,0 @@
<vector android:height="24dp" android:viewportHeight="20.0"
android:viewportWidth="20.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFF" android:pathData="M4.516,7.548c0.436,-0.446 1.043,-0.481 1.576,0L10,11.295l3.908,-3.747c0.533,-0.481 1.141,-0.446 1.574,0c0.436,0.445 0.408,1.197 0,1.615c-0.406,0.418 -4.695,4.502 -4.695,4.502C10.57,13.888 10.285,14 10,14s-0.57,-0.112 -0.789,-0.335c0,0 -4.287,-4.084 -4.695,-4.502C4.107,8.745 4.08,7.993 4.516,7.548z"/>
</vector>

View File

@ -1,4 +0,0 @@
<vector android:height="24dp" android:viewportHeight="20.0"
android:viewportWidth="20.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFF" android:pathData="M14,5h-4v2h4V5zM14,8h-4v1h4V8zM9,5H6v4h3V5zM9,11h5v-1H9V11zM12,13h2v-1h-2V13zM14,14H6v1h8V14zM11,12H6v1h5V12zM8,10H6v1h2V10zM17,1H3C2.447,1 2,1.447 2,2v16c0,0.552 0.447,1 1,1h14c0.553,0 1,-0.448 1,-1V2C18,1.448 17.553,1 17,1zM16,17H4V3h12V17z"/>
</vector>

View File

@ -1,4 +0,0 @@
<vector android:height="24dp" android:viewportHeight="20.0"
android:viewportWidth="20.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFF" android:pathData="M7.725,2.146c-1.016,0.756 -1.289,1.953 -1.239,2.59C6.55,5.515 6.708,6.529 6.708,6.529s-0.313,0.17 -0.313,0.854C6.504,9.1 7.078,8.359 7.196,9.112c0.284,1.814 0.933,1.491 0.933,2.481c0,1.649 -0.68,2.42 -2.803,3.334C3.196,15.845 1,17 1,19v1h18v-1c0,-2 -2.197,-3.155 -4.328,-4.072c-2.123,-0.914 -2.801,-1.684 -2.801,-3.334c0,-0.99 0.647,-0.667 0.932,-2.481c0.119,-0.753 0.692,-0.012 0.803,-1.729c0,-0.684 -0.314,-0.854 -0.314,-0.854s0.158,-1.014 0.221,-1.793c0.065,-0.817 -0.398,-2.561 -2.3,-3.096c-0.333,-0.34 -0.558,-0.881 0.466,-1.424C9.439,0.112 8.918,1.284 7.725,2.146z"/>
</vector>

View File

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

View File

@ -25,7 +25,7 @@
</style>
<style name="CardViewStyle" parent="CardView">
<item name="cardBackgroundColor">#4f000000</item>
<item name="cardBackgroundColor">#40000000</item>
<item name="cardCornerRadius">4dp</item>
<item name="cardElevation">2dp</item>
<item name="cardUseCompatPadding">true</item>

View File

@ -14,7 +14,7 @@ allprojects {
repositories {
jcenter()
google()
flatDir{ dirs 'libs'}
//flatDir{ dirs 'libs'}
}
}