mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-30 02:44:59 +01:00
bugfix, code cleanup
This commit is contained in:
parent
41b4c34f96
commit
d4617560fe
@ -3,6 +3,7 @@ package org.nuclearfog.twidda;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
|
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
@ -15,6 +16,7 @@ import android.view.ViewGroup;
|
|||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.TranslateAnimation;
|
import android.view.animation.TranslateAnimation;
|
||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
|
import android.widget.TabHost.OnTabChangeListener;
|
||||||
import android.widget.TabHost.TabSpec;
|
import android.widget.TabHost.TabSpec;
|
||||||
|
|
||||||
import org.nuclearfog.twidda.backend.GlobalSettings;
|
import org.nuclearfog.twidda.backend.GlobalSettings;
|
||||||
@ -30,8 +32,7 @@ import org.nuclearfog.twidda.window.TweetDetail;
|
|||||||
import org.nuclearfog.twidda.window.TweetPopup;
|
import org.nuclearfog.twidda.window.TweetPopup;
|
||||||
import org.nuclearfog.twidda.window.UserProfile;
|
import org.nuclearfog.twidda.window.UserProfile;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements
|
public class MainActivity extends AppCompatActivity implements OnRefreshListener, OnTabChangeListener,
|
||||||
SwipeRefreshLayout.OnRefreshListener, TabHost.OnTabChangeListener,
|
|
||||||
TimelineRecycler.OnItemClicked, TrendRecycler.OnItemClicked
|
TimelineRecycler.OnItemClicked, TrendRecycler.OnItemClicked
|
||||||
{
|
{
|
||||||
private SwipeRefreshLayout timelineReload,trendReload,mentionReload;
|
private SwipeRefreshLayout timelineReload,trendReload,mentionReload;
|
||||||
@ -55,21 +56,61 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
TwitterEngine mTwitter = TwitterEngine.getInstance(this);
|
TwitterEngine mTwitter = TwitterEngine.getInstance(this);
|
||||||
settings = GlobalSettings.getInstance(this);
|
settings = GlobalSettings.getInstance(this);
|
||||||
boolean login = mTwitter.loggedIn();
|
boolean login = mTwitter.loggedIn();
|
||||||
|
|
||||||
if( !login ) {
|
if( !login ) {
|
||||||
Intent i = new Intent(this, LoginPage.class);
|
Intent i = new Intent(this, LoginPage.class);
|
||||||
startActivityForResult(i,REQ_CODE);
|
startActivityForResult(i,REQ_CODE);
|
||||||
} else {
|
|
||||||
login();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
homeId = settings.getUserId();
|
||||||
|
timelineList = findViewById(R.id.tl_list);
|
||||||
|
trendList = findViewById(R.id.tr_list);
|
||||||
|
mentionList = findViewById(R.id.m_list);
|
||||||
|
timelineReload = findViewById(R.id.timeline);
|
||||||
|
trendReload = findViewById(R.id.trends);
|
||||||
|
mentionReload = findViewById(R.id.mention);
|
||||||
|
tabhost = findViewById(R.id.main_tabhost);
|
||||||
|
toolbar = findViewById(R.id.profile_toolbar);
|
||||||
|
|
||||||
|
timelineList.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
timelineList.setHasFixedSize(true);
|
||||||
|
|
||||||
|
trendList.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
trendList.setHasFixedSize(true);
|
||||||
|
|
||||||
|
mentionList.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
mentionList.setHasFixedSize(true);
|
||||||
|
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
if (getSupportActionBar() != null)
|
||||||
|
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||||
|
|
||||||
|
tabhost.setup();
|
||||||
|
TabSpec tab1 = tabhost.newTabSpec("timeline");
|
||||||
|
tab1.setContent(R.id.timeline);
|
||||||
|
tab1.setIndicator("", getDrawable(R.drawable.home));
|
||||||
|
tabhost.addTab(tab1);
|
||||||
|
TabSpec tab2 = tabhost.newTabSpec("trends");
|
||||||
|
tab2.setContent(R.id.trends);
|
||||||
|
tab2.setIndicator("", getDrawable(R.drawable.hash));
|
||||||
|
tabhost.addTab(tab2);
|
||||||
|
TabSpec tab3 = tabhost.newTabSpec("mention");
|
||||||
|
tab3.setContent(R.id.mention);
|
||||||
|
tab3.setIndicator("", getDrawable(R.drawable.mention));
|
||||||
|
tabhost.addTab(tab3);
|
||||||
|
|
||||||
|
tabhost.setOnTabChangedListener(this);
|
||||||
|
timelineReload.setOnRefreshListener(this);
|
||||||
|
trendReload.setOnRefreshListener(this);
|
||||||
|
mentionReload.setOnRefreshListener(this);
|
||||||
|
setTabContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int reqCode, int returnCode, Intent i) {
|
protected void onActivityResult(int reqCode, int returnCode, Intent i) {
|
||||||
super.onActivityResult(reqCode,returnCode,i);
|
super.onActivityResult(reqCode,returnCode,i);
|
||||||
if(reqCode == REQ_CODE) {
|
if(reqCode == REQ_CODE) {
|
||||||
if(returnCode == RESULT_OK) {
|
if (returnCode != RESULT_OK) {
|
||||||
login();
|
|
||||||
} else {
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,52 +316,6 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void login() {
|
|
||||||
homeId = settings.getUserId();
|
|
||||||
timelineList = findViewById(R.id.tl_list);
|
|
||||||
trendList = findViewById(R.id.tr_list);
|
|
||||||
mentionList = findViewById(R.id.m_list);
|
|
||||||
timelineReload = findViewById(R.id.timeline);
|
|
||||||
trendReload = findViewById(R.id.trends);
|
|
||||||
mentionReload = findViewById(R.id.mention);
|
|
||||||
tabhost = findViewById(R.id.main_tabhost);
|
|
||||||
toolbar = findViewById(R.id.profile_toolbar);
|
|
||||||
|
|
||||||
timelineList.setLayoutManager(new LinearLayoutManager(this));
|
|
||||||
timelineList.setHasFixedSize(true);
|
|
||||||
|
|
||||||
trendList.setLayoutManager(new LinearLayoutManager(this));
|
|
||||||
trendList.setHasFixedSize(true);
|
|
||||||
|
|
||||||
mentionList.setLayoutManager(new LinearLayoutManager(this));
|
|
||||||
mentionList.setHasFixedSize(true);
|
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
if(getSupportActionBar() != null)
|
|
||||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
|
||||||
|
|
||||||
tabhost.setup();
|
|
||||||
TabSpec tab1 = tabhost.newTabSpec("timeline");
|
|
||||||
tab1.setContent(R.id.timeline);
|
|
||||||
tab1.setIndicator("",getDrawable(R.drawable.home));
|
|
||||||
tabhost.addTab(tab1);
|
|
||||||
TabSpec tab2 = tabhost.newTabSpec("trends");
|
|
||||||
tab2.setContent(R.id.trends);
|
|
||||||
tab2.setIndicator("",getDrawable(R.drawable.hash));
|
|
||||||
tabhost.addTab(tab2);
|
|
||||||
TabSpec tab3 = tabhost.newTabSpec("mention");
|
|
||||||
tab3.setContent(R.id.mention);
|
|
||||||
tab3.setIndicator("",getDrawable(R.drawable.mention));
|
|
||||||
tabhost.addTab(tab3);
|
|
||||||
|
|
||||||
tabhost.setOnTabChangedListener(this);
|
|
||||||
timelineReload.setOnRefreshListener(this);
|
|
||||||
trendReload.setOnRefreshListener(this);
|
|
||||||
mentionReload.setOnRefreshListener(this);
|
|
||||||
setTabContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void setTabContent() {
|
private void setTabContent() {
|
||||||
int background = settings.getBackgroundColor();
|
int background = settings.getBackgroundColor();
|
||||||
int fontColor = settings.getFontColor();
|
int fontColor = settings.getFontColor();
|
||||||
|
@ -4,12 +4,17 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class GlobalSettings {
|
public class GlobalSettings {
|
||||||
|
|
||||||
private static GlobalSettings ourInstance;
|
private static GlobalSettings ourInstance;
|
||||||
|
|
||||||
private SharedPreferences settings;
|
private SharedPreferences settings;
|
||||||
|
|
||||||
|
private SimpleDateFormat sdf;
|
||||||
|
|
||||||
private int background_color;
|
private int background_color;
|
||||||
private int font_color;
|
private int font_color;
|
||||||
private int highlight_color;
|
private int highlight_color;
|
||||||
@ -40,6 +45,7 @@ public class GlobalSettings {
|
|||||||
key1 = settings.getString("key1","");
|
key1 = settings.getString("key1","");
|
||||||
key2 = settings.getString("key2","");
|
key2 = settings.getString("key2","");
|
||||||
userId = settings.getLong("userID",-1L);
|
userId = settings.getLong("userID",-1L);
|
||||||
|
sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss", Locale.GERMANY); // TODO editable date format
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBackgroundColor() {
|
public int getBackgroundColor() {
|
||||||
@ -89,6 +95,10 @@ public class GlobalSettings {
|
|||||||
return userId;
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SimpleDateFormat getDateFormatter() {
|
||||||
|
return sdf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setBackgroundColor(int color) {
|
public void setBackgroundColor(int color) {
|
||||||
Editor edit = settings.edit();
|
Editor edit = settings.edit();
|
||||||
|
@ -25,7 +25,6 @@ import java.lang.ref.WeakReference;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import twitter4j.TwitterException;
|
import twitter4j.TwitterException;
|
||||||
|
|
||||||
@ -44,9 +43,9 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
|||||||
private String profileImage, link, dateString;
|
private String profileImage, link, dateString;
|
||||||
private TimelineRecycler homeTl, homeFav;
|
private TimelineRecycler homeTl, homeFav;
|
||||||
private WeakReference<UserProfile> ui;
|
private WeakReference<UserProfile> ui;
|
||||||
|
private SimpleDateFormat sdf;
|
||||||
private TwitterEngine mTwitter;
|
private TwitterEngine mTwitter;
|
||||||
private ErrorLog errorLog;
|
private ErrorLog errorLog;
|
||||||
private int font, highlight;
|
|
||||||
private long homeId;
|
private long homeId;
|
||||||
private boolean imgEnabled;
|
private boolean imgEnabled;
|
||||||
private boolean isHome = false;
|
private boolean isHome = false;
|
||||||
@ -66,9 +65,10 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
|||||||
ui = new WeakReference<>((UserProfile)context);
|
ui = new WeakReference<>((UserProfile)context);
|
||||||
mTwitter = TwitterEngine.getInstance(context);
|
mTwitter = TwitterEngine.getInstance(context);
|
||||||
GlobalSettings settings = GlobalSettings.getInstance(context);
|
GlobalSettings settings = GlobalSettings.getInstance(context);
|
||||||
|
sdf = settings.getDateFormatter();
|
||||||
errorLog = new ErrorLog(ui.get());
|
errorLog = new ErrorLog(ui.get());
|
||||||
font = settings.getFontColor();
|
int font = settings.getFontColor();
|
||||||
highlight = settings.getHighlightColor();
|
int highlight = settings.getHighlightColor();
|
||||||
imgEnabled = settings.loadImages();
|
imgEnabled = settings.loadImages();
|
||||||
homeId = settings.getUserId();
|
homeId = settings.getUserId();
|
||||||
RecyclerView profileTweets = ui.get().findViewById(R.id.ht_list);
|
RecyclerView profileTweets = ui.get().findViewById(R.id.ht_list);
|
||||||
@ -78,10 +78,14 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
|||||||
|
|
||||||
if(homeTl == null) {
|
if(homeTl == null) {
|
||||||
homeTl = new TimelineRecycler(ui.get());
|
homeTl = new TimelineRecycler(ui.get());
|
||||||
|
homeTl.setColor(highlight, font);
|
||||||
|
homeTl.toggleImage(imgEnabled);
|
||||||
profileTweets.setAdapter(homeTl);
|
profileTweets.setAdapter(homeTl);
|
||||||
}
|
}
|
||||||
if(homeFav == null) {
|
if(homeFav == null) {
|
||||||
homeFav = new TimelineRecycler(ui.get());
|
homeFav = new TimelineRecycler(ui.get());
|
||||||
|
homeFav.setColor(highlight, font);
|
||||||
|
homeFav.toggleImage(imgEnabled);
|
||||||
profileFavorits.setAdapter(homeFav);
|
profileFavorits.setAdapter(homeFav);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,12 +126,11 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
|||||||
follower = Integer.toString(user.follower);
|
follower = Integer.toString(user.follower);
|
||||||
following = Integer.toString(user.following);
|
following = Integer.toString(user.following);
|
||||||
profileImage = user.profileImg;
|
profileImage = user.profileImg;
|
||||||
Date d = new Date(user.created);
|
Date time = new Date(user.created);
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss", Locale.GERMANY);
|
dateString = "seit " + sdf.format(time);
|
||||||
dateString = "seit "+ sdf.format(d);
|
|
||||||
description = description.replace('\n', ' ');
|
description = description.replace('\n', ' ');
|
||||||
|
|
||||||
if(MODE == GET_TWEETS)
|
if (MODE == GET_TWEETS && !isLocked)
|
||||||
{
|
{
|
||||||
List<Tweet> tweets;
|
List<Tweet> tweets;
|
||||||
|
|
||||||
@ -144,18 +147,15 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
homeTl.setData(tweets);
|
homeTl.setData(tweets);
|
||||||
homeTl.setColor(highlight,font);
|
} else if (MODE == GET_FAVS && !isLocked)
|
||||||
homeTl.toggleImage(imgEnabled);
|
|
||||||
}
|
|
||||||
else if(MODE == GET_FAVS)
|
|
||||||
{
|
{
|
||||||
List<Tweet> favorits;
|
List<Tweet> favorits;
|
||||||
|
|
||||||
if(homeFav.getItemCount() > 0) {
|
if(homeFav.getItemCount() > 0) {
|
||||||
id = homeFav.getItemId(0);
|
id = homeFav.getItemId(0);
|
||||||
favorits = mTwitter.getUserFavs(userId,args[2],id);
|
favorits = mTwitter.getUserFavs(userId,args[2],id);
|
||||||
database.storeUserFavs(favorits,userId);
|
database.storeUserFavs(favorits,userId);
|
||||||
favorits.addAll(homeFav.getData());
|
favorits.addAll(homeFav.getData());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
favorits = database.getUserFavs(userId);
|
favorits = database.getUserFavs(userId);
|
||||||
if(favorits.size() == 0 && !isLocked) {
|
if(favorits.size() == 0 && !isLocked) {
|
||||||
@ -164,8 +164,6 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
homeFav.setData(favorits);
|
homeFav.setData(favorits);
|
||||||
homeFav.setColor(highlight,font);
|
|
||||||
homeFav.toggleImage(imgEnabled);
|
|
||||||
}
|
}
|
||||||
else if(MODE == ACTION_FOLLOW)
|
else if(MODE == ACTION_FOLLOW)
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,6 @@ import org.nuclearfog.twidda.window.TweetDetail;
|
|||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import twitter4j.TwitterException;
|
import twitter4j.TwitterException;
|
||||||
|
|
||||||
@ -65,7 +64,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
|
|||||||
public StatusLoader(Context context) {
|
public StatusLoader(Context context) {
|
||||||
mTwitter = TwitterEngine.getInstance(context);
|
mTwitter = TwitterEngine.getInstance(context);
|
||||||
GlobalSettings settings = GlobalSettings.getInstance(context);
|
GlobalSettings settings = GlobalSettings.getInstance(context);
|
||||||
sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss", Locale.GERMANY);
|
sdf = settings.getDateFormatter();
|
||||||
font = settings.getFontColor();
|
font = settings.getFontColor();
|
||||||
highlight = settings.getHighlightColor();
|
highlight = settings.getHighlightColor();
|
||||||
toggleImg = settings.loadImages();
|
toggleImg = settings.loadImages();
|
||||||
|
@ -8,8 +8,6 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.nuclearfog.twidda.R;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class LogAdapter extends Adapter<LogAdapter.ItemHolder> {
|
public class LogAdapter extends Adapter<LogAdapter.ItemHolder> {
|
||||||
@ -28,7 +26,7 @@ public class LogAdapter extends Adapter<LogAdapter.ItemHolder> {
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public LogAdapter.ItemHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public LogAdapter.ItemHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_error, parent,false);
|
View v = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
|
||||||
return new ItemHolder(v);
|
return new ItemHolder(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,13 +34,14 @@ public class LogAdapter extends Adapter<LogAdapter.ItemHolder> {
|
|||||||
public void onBindViewHolder(@NonNull ItemHolder vh, int index) {
|
public void onBindViewHolder(@NonNull ItemHolder vh, int index) {
|
||||||
vh.message.setText(messages.get(index));
|
vh.message.setText(messages.get(index));
|
||||||
vh.message.setTextColor(0xffff0000);
|
vh.message.setTextColor(0xffff0000);
|
||||||
|
vh.message.setTextSize(12.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ItemHolder extends RecyclerView.ViewHolder {
|
class ItemHolder extends RecyclerView.ViewHolder {
|
||||||
public final TextView message;
|
public final TextView message;
|
||||||
ItemHolder(View v) {
|
ItemHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
message = v.findViewById(R.id.errortext);
|
message = v.findViewById(android.R.id.text1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
style="@style/CardViewStyle"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_margin="5dp"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/errortext"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</android.support.v7.widget.CardView>
|
|
Loading…
x
Reference in New Issue
Block a user