Code Cleanup
New Image Preview for Tweets and Profile Images!
This commit is contained in:
NudeDude 2018-02-24 17:15:01 +01:00
parent 049872a436
commit 8bf80933e5
15 changed files with 131 additions and 111 deletions

View File

@ -14,14 +14,11 @@ import org.nuclearfog.twidda.viewadapter.TimelineAdapter;
import org.nuclearfog.twidda.viewadapter.UserAdapter;
import org.nuclearfog.twidda.window.SearchWindow;
public class TwitterSearch extends AsyncTask<String, Void, String> {
public static final String TWEETS = "tweets";
public static final String USERS = "users";
public class TwitterSearch extends AsyncTask<String, Void, Void> {
private TimelineAdapter tlAdp;
private UserAdapter uAdp;
private SwipeRefreshLayout tweetReload, userReload;
private SwipeRefreshLayout tweetReload;
private ListView tweetSearch, userSearch;
private ProgressBar circleLoad;
private Context context;
@ -36,49 +33,35 @@ public class TwitterSearch extends AsyncTask<String, Void, String> {
tweetSearch = (ListView) ((SearchWindow)context).findViewById(R.id.tweet_result);
userSearch = (ListView) ((SearchWindow)context).findViewById(R.id.user_result);
tweetReload = (SwipeRefreshLayout) ((SearchWindow)context).findViewById(R.id.searchtweets);
userReload = (SwipeRefreshLayout) ((SearchWindow)context).findViewById(R.id.searchusers);
circleLoad = (ProgressBar) ((SearchWindow)context).findViewById(R.id.search_progress);
mTwitter = TwitterEngine.getInstance(context);
}
@Override
protected String doInBackground(String... search) {
String mode = search[0];
String get = search[1];
protected Void doInBackground(String... search) {
String get = search[0];
long id = 1L;
try {
switch(mode) {
case(TWEETS):
tlAdp = (TimelineAdapter) tweetSearch.getAdapter();
if(tlAdp != null) {
id = tlAdp.getItemId(0);
tlAdp.getData().addHot(mTwitter.searchTweets(get,id));
} else {
tlAdp = new TimelineAdapter(context, new TweetDatabase(mTwitter.searchTweets(get,id),context));
}
return TWEETS;
case(USERS):
uAdp = new UserAdapter(context, new UserDatabase(context, mTwitter.searchUsers(get)));
return USERS;
tlAdp = (TimelineAdapter) tweetSearch.getAdapter();
if(tlAdp != null) {
id = tlAdp.getItemId(0);
tlAdp.getData().addHot(mTwitter.searchTweets(get,id));
} else {
tlAdp = new TimelineAdapter(context, new TweetDatabase(mTwitter.searchTweets(get,id),context));
}
uAdp = new UserAdapter(context, new UserDatabase(context, mTwitter.searchUsers(get)));
} catch(Exception err){err.printStackTrace();}
return "";
return null;
}
@Override
protected void onPostExecute(String mode) {
protected void onPostExecute(Void v) {
circleLoad.setVisibility(View.INVISIBLE);
switch(mode) {
case(TWEETS):
if(tweetSearch.getAdapter() == null)
tweetSearch.setAdapter(tlAdp);
else
tlAdp.notifyDataSetChanged();
tweetReload.setRefreshing(false);
break;
case(USERS):
userSearch.setAdapter(uAdp);
userReload.setRefreshing(false);
}
if(tweetSearch.getAdapter() == null)
tweetSearch.setAdapter(tlAdp);
else
tlAdp.notifyDataSetChanged();
userSearch.setAdapter(uAdp);
tweetReload.setRefreshing(false);
}
}

View File

@ -36,7 +36,7 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
@Override
protected void onPreExecute() {
mTwitter = TwitterEngine.getInstance(context);
userList = (ListView)((UserDetail)context).findViewById(R.id.followList);
userList = (ListView)((UserDetail)context).findViewById(R.id.userlist);
uProgress = (ProgressBar)((UserDetail)context).findViewById(R.id.user_progress);
}

View File

@ -4,12 +4,14 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TabHost;
import org.nuclearfog.twidda.R;
@ -21,55 +23,66 @@ import org.nuclearfog.twidda.backend.TwitterSearch;
/**
* SearchWindow Tweets and Users
* @see org.nuclearfog.twidda.backend.TwitterSearch
* @see TwitterSearch
*/
public class SearchWindow extends AppCompatActivity implements AdapterView.OnItemClickListener,
SwipeRefreshLayout.OnRefreshListener, TabHost.OnTabChangeListener {
private ListView tweetSearch, userSearch;
private SwipeRefreshLayout tweetReload,userReload;
private String search;
private String currentTab = "search_result";
private SwipeRefreshLayout tweetReload;
private TwitterSearch mSearch;
private String search = "";
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.search);
if(getSupportActionBar() != null)
getSupportActionBar().setDisplayShowTitleEnabled(false);
search = getIntent().getExtras().getString("search");
Toolbar tool = (Toolbar) findViewById(R.id.search_toolbar);
tweetSearch = (ListView) findViewById(R.id.tweet_result);
userSearch = (ListView) findViewById(R.id.user_result);
tweetReload = (SwipeRefreshLayout) findViewById(R.id.searchtweets);
userReload = (SwipeRefreshLayout) findViewById(R.id.searchusers);
setSupportActionBar(tool);
TabHost tabhost = (TabHost)findViewById(R.id.search_tab);
tabhost.setup();
setSupportActionBar(tool);
getSupportActionBar().setDisplayShowTitleEnabled(false);
TabHost.TabSpec tab1 = tabhost.newTabSpec("search_result");
tab1.setContent(R.id.searchtweets);
tab1.setIndicator("",getResources().getDrawable(R.drawable.search));
tabhost.addTab(tab1);
TabHost.TabSpec tab2 = tabhost.newTabSpec("user_result");
tab2.setContent(R.id.searchusers);
tab2.setIndicator("",getResources().getDrawable(R.drawable.user));
tabhost.addTab(tab2);
setTabs(tabhost);
tabhost.setOnTabChangedListener(this);
tweetSearch.setOnItemClickListener(this);
userSearch.setOnItemClickListener(this);
tweetReload.setOnRefreshListener(this);
userReload.setOnRefreshListener(this);
getContent(TwitterSearch.TWEETS);
getContent(TwitterSearch.USERS);
getContent();
}
@Override
protected void onDestroy() {
mSearch.cancel(true);
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu m) {
getMenuInflater().inflate(R.menu.search, m);
SearchView searchQuery = (SearchView)m.findItem(R.id.new_search).getActionView();
searchQuery.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
search = s;
ProgressBar mCircle = (ProgressBar)findViewById(R.id.search_progress);
mCircle.setVisibility(View.VISIBLE);
tweetSearch.setAdapter(null);
getContent();
return false;
}
@Override
public boolean onQueryTextChange(String s) {
return false;
}
});
return true;
}
@ -110,40 +123,43 @@ public class SearchWindow extends AppCompatActivity implements AdapterView.OnIte
}
break;
case R.id.user_result:
if(!userReload.isRefreshing()) {
UserAdapter uAdp = (UserAdapter) userSearch.getAdapter();
UserDatabase uDb = uAdp.getData();
Intent profile = new Intent(getApplicationContext(), UserProfile.class);
Bundle bundle = new Bundle();
long userID = uDb.getUserID(position);
bundle.putLong("userID",userID);
profile.putExtras(bundle);
startActivity(profile);
}
UserAdapter uAdp = (UserAdapter) userSearch.getAdapter();
UserDatabase uDb = uAdp.getData();
Intent profile = new Intent(getApplicationContext(), UserProfile.class);
Bundle bundle = new Bundle();
long userID = uDb.getUserID(position);
bundle.putLong("userID",userID);
profile.putExtras(bundle);
startActivity(profile);
break;
}
}
@Override
public void onRefresh() {
switch(currentTab){
case "search_result":
getContent(org.nuclearfog.twidda.backend.TwitterSearch.TWEETS);
break;
case "user_result":
getContent(org.nuclearfog.twidda.backend.TwitterSearch.USERS);
break;
}
getContent();
}
@Override
public void onTabChanged(String tabId) {
tweetReload.setRefreshing(false);
userReload.setRefreshing(false);
currentTab = tabId;
if(tabId.equals("user_result"))
tweetReload.setRefreshing(false);
}
private void getContent(final String MODE) {
new TwitterSearch(SearchWindow.this).execute(MODE,search);
private void setTabs(TabHost tabhost) {
TabHost.TabSpec tab1 = tabhost.newTabSpec("search_result");
tab1.setContent(R.id.searchtweets);
tab1.setIndicator("",getResources().getDrawable(R.drawable.search));
tabhost.addTab(tab1);
TabHost.TabSpec tab2 = tabhost.newTabSpec("user_result");
tab2.setContent(R.id.user_result);
tab2.setIndicator("",getResources().getDrawable(R.drawable.user));
tabhost.addTab(tab2);
}
private void getContent() {
mSearch = new TwitterSearch(this);
mSearch.execute(search);
}
}

View File

@ -35,7 +35,7 @@ public class UserDetail extends AppCompatActivity implements AdapterView.OnItemC
if(i.hasExtra("tweetID")){
tweetID = i.getExtras().getLong("tweetID");
}
userListview = (ListView) findViewById(R.id.followList);
userListview = (ListView) findViewById(R.id.userlist);
userListview.setOnItemClickListener(this);
toolbar = (Toolbar) findViewById(R.id.follow_toolbar);
setSupportActionBar(toolbar);

View File

@ -7,7 +7,6 @@ import android.support.design.widget.AppBarLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -62,6 +61,7 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
homeFavorits.setOnItemClickListener(this);
homeReload.setOnRefreshListener(this);
favoriteReload.setOnRefreshListener(this);
initElements();
getContent();
}

View File

@ -8,8 +8,8 @@
<ImageView
android:id="@+id/downarrow"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/downarrow"
app:srcCompat="@drawable/downarrow" />
</LinearLayout>

View File

@ -37,7 +37,8 @@
<ListView
android:id="@+id/tl_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:background="@color/twitterBlau" />
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.v4.widget.SwipeRefreshLayout
@ -48,7 +49,8 @@
<ListView
android:id="@+id/tr_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:background="@color/twitterBlau" />
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.v4.widget.SwipeRefreshLayout
@ -59,7 +61,8 @@
<ListView
android:id="@+id/m_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:background="@color/twitterBlau" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>

View File

@ -212,6 +212,7 @@
android:id="@+id/ht_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/twitterBlau"
android:nestedScrollingEnabled="true" />
</android.support.v4.widget.SwipeRefreshLayout>
@ -224,6 +225,7 @@
android:id="@+id/hf_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/twitterBlau"
android:nestedScrollingEnabled="true" />
</android.support.v4.widget.SwipeRefreshLayout>

View File

@ -38,27 +38,22 @@
<ListView
android:id="@+id/tweet_result"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="@color/twitterBlau">
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/searchusers"
<ListView
android:id="@+id/user_result"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="@color/twitterBlau">
<ListView
android:id="@+id/user_result"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
</LinearLayout>

View File

@ -21,17 +21,19 @@
<Button
android:id="@+id/color_background"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="@string/background" />
<Button
android:id="@+id/color_font"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:includeFontPadding="false"
android:text="@string/font"
android:textColor="@android:color/black" />
@ -41,23 +43,26 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="@+id/color_tweet"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="@string/popup" />
<Button
android:id="@+id/highlight_color"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="@string/highlight" />
</LinearLayout>
@ -109,7 +114,8 @@
android:id="@+id/woeid"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:inputType="number" />
android:inputType="number"
android:labelFor="@id/textView" />
<TextView
android:id="@+id/textView"

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
@ -22,9 +23,13 @@
android:layout_gravity="center" />
<ListView
android:id="@+id/followList"
android:id="@+id/userlist"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:background="@color/twitterBlau">
</ListView>
</FrameLayout>
</LinearLayout>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item

View File

@ -2,6 +2,13 @@
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/new_search"
android:icon="@drawable/search"
android:title="@string/search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" />
<item
android:id="@+id/search_tweet"
android:icon="@drawable/tweet"

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorPrimaryDark">#303f9f</color>
<color name="colorAccent">#ff4081</color>
<color name="twitterBlau">#034059</color>
<color name="soylentgreen">#76b900</color>
<color name="soylentgreen">#76ff03</color>
<color name="tweetwindow">#19aae8</color>
<color name="following">#00ffff</color>
<color name="muted">#ff0000</color>
<color name="transparent">#00000000</color>
<color name="DarkBlue">#050f48</color>
</resources>

View File

@ -2,8 +2,11 @@
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorAccent">@color/soylentgreen</item>
<item name="android:windowAnimationStyle">@style/TransactionPending</item>
<item name="android:navigationBarColor">@android:color/background_dark</item>
<item name="android:colorBackground">@color/DarkBlue</item>
<item name="android:statusBarColor">@color/transparent</item>
</style>
<style name="Transparency" parent="AppTheme">