mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-29 02:19:35 +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.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@ -15,6 +16,7 @@ import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.TranslateAnimation;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.TabHost.OnTabChangeListener;
|
||||
import android.widget.TabHost.TabSpec;
|
||||
|
||||
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.UserProfile;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements
|
||||
SwipeRefreshLayout.OnRefreshListener, TabHost.OnTabChangeListener,
|
||||
public class MainActivity extends AppCompatActivity implements OnRefreshListener, OnTabChangeListener,
|
||||
TimelineRecycler.OnItemClicked, TrendRecycler.OnItemClicked
|
||||
{
|
||||
private SwipeRefreshLayout timelineReload,trendReload,mentionReload;
|
||||
@ -55,21 +56,61 @@ public class MainActivity extends AppCompatActivity implements
|
||||
TwitterEngine mTwitter = TwitterEngine.getInstance(this);
|
||||
settings = GlobalSettings.getInstance(this);
|
||||
boolean login = mTwitter.loggedIn();
|
||||
|
||||
if( !login ) {
|
||||
Intent i = new Intent(this, LoginPage.class);
|
||||
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
|
||||
protected void onActivityResult(int reqCode, int returnCode, Intent i) {
|
||||
super.onActivityResult(reqCode,returnCode,i);
|
||||
if(reqCode == REQ_CODE) {
|
||||
if(returnCode == RESULT_OK) {
|
||||
login();
|
||||
} else {
|
||||
if (returnCode != RESULT_OK) {
|
||||
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() {
|
||||
int background = settings.getBackgroundColor();
|
||||
int fontColor = settings.getFontColor();
|
||||
|
@ -4,12 +4,17 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
public class GlobalSettings {
|
||||
|
||||
private static GlobalSettings ourInstance;
|
||||
|
||||
private SharedPreferences settings;
|
||||
|
||||
private SimpleDateFormat sdf;
|
||||
|
||||
private int background_color;
|
||||
private int font_color;
|
||||
private int highlight_color;
|
||||
@ -40,6 +45,7 @@ public class GlobalSettings {
|
||||
key1 = settings.getString("key1","");
|
||||
key2 = settings.getString("key2","");
|
||||
userId = settings.getLong("userID",-1L);
|
||||
sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss", Locale.GERMANY); // TODO editable date format
|
||||
}
|
||||
|
||||
public int getBackgroundColor() {
|
||||
@ -89,6 +95,10 @@ public class GlobalSettings {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public SimpleDateFormat getDateFormatter() {
|
||||
return sdf;
|
||||
}
|
||||
|
||||
|
||||
public void setBackgroundColor(int color) {
|
||||
Editor edit = settings.edit();
|
||||
|
@ -25,7 +25,6 @@ import java.lang.ref.WeakReference;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import twitter4j.TwitterException;
|
||||
|
||||
@ -44,9 +43,9 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||
private String profileImage, link, dateString;
|
||||
private TimelineRecycler homeTl, homeFav;
|
||||
private WeakReference<UserProfile> ui;
|
||||
private SimpleDateFormat sdf;
|
||||
private TwitterEngine mTwitter;
|
||||
private ErrorLog errorLog;
|
||||
private int font, highlight;
|
||||
private long homeId;
|
||||
private boolean imgEnabled;
|
||||
private boolean isHome = false;
|
||||
@ -66,9 +65,10 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||
ui = new WeakReference<>((UserProfile)context);
|
||||
mTwitter = TwitterEngine.getInstance(context);
|
||||
GlobalSettings settings = GlobalSettings.getInstance(context);
|
||||
sdf = settings.getDateFormatter();
|
||||
errorLog = new ErrorLog(ui.get());
|
||||
font = settings.getFontColor();
|
||||
highlight = settings.getHighlightColor();
|
||||
int font = settings.getFontColor();
|
||||
int highlight = settings.getHighlightColor();
|
||||
imgEnabled = settings.loadImages();
|
||||
homeId = settings.getUserId();
|
||||
RecyclerView profileTweets = ui.get().findViewById(R.id.ht_list);
|
||||
@ -78,10 +78,14 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||
|
||||
if(homeTl == null) {
|
||||
homeTl = new TimelineRecycler(ui.get());
|
||||
homeTl.setColor(highlight, font);
|
||||
homeTl.toggleImage(imgEnabled);
|
||||
profileTweets.setAdapter(homeTl);
|
||||
}
|
||||
if(homeFav == null) {
|
||||
homeFav = new TimelineRecycler(ui.get());
|
||||
homeFav.setColor(highlight, font);
|
||||
homeFav.toggleImage(imgEnabled);
|
||||
profileFavorits.setAdapter(homeFav);
|
||||
}
|
||||
}
|
||||
@ -122,12 +126,11 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||
follower = Integer.toString(user.follower);
|
||||
following = Integer.toString(user.following);
|
||||
profileImage = user.profileImg;
|
||||
Date d = new Date(user.created);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss", Locale.GERMANY);
|
||||
dateString = "seit "+ sdf.format(d);
|
||||
Date time = new Date(user.created);
|
||||
dateString = "seit " + sdf.format(time);
|
||||
description = description.replace('\n', ' ');
|
||||
|
||||
if(MODE == GET_TWEETS)
|
||||
if (MODE == GET_TWEETS && !isLocked)
|
||||
{
|
||||
List<Tweet> tweets;
|
||||
|
||||
@ -144,18 +147,15 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||
}
|
||||
}
|
||||
homeTl.setData(tweets);
|
||||
homeTl.setColor(highlight,font);
|
||||
homeTl.toggleImage(imgEnabled);
|
||||
}
|
||||
else if(MODE == GET_FAVS)
|
||||
} else if (MODE == GET_FAVS && !isLocked)
|
||||
{
|
||||
List<Tweet> favorits;
|
||||
|
||||
if(homeFav.getItemCount() > 0) {
|
||||
id = homeFav.getItemId(0);
|
||||
favorits = mTwitter.getUserFavs(userId,args[2],id);
|
||||
database.storeUserFavs(favorits,userId);
|
||||
favorits.addAll(homeFav.getData());
|
||||
|
||||
} else {
|
||||
favorits = database.getUserFavs(userId);
|
||||
if(favorits.size() == 0 && !isLocked) {
|
||||
@ -164,8 +164,6 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
|
||||
}
|
||||
}
|
||||
homeFav.setData(favorits);
|
||||
homeFav.setColor(highlight,font);
|
||||
homeFav.toggleImage(imgEnabled);
|
||||
}
|
||||
else if(MODE == ACTION_FOLLOW)
|
||||
{
|
||||
|
@ -31,7 +31,6 @@ import org.nuclearfog.twidda.window.TweetDetail;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import twitter4j.TwitterException;
|
||||
|
||||
@ -65,7 +64,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
|
||||
public StatusLoader(Context context) {
|
||||
mTwitter = TwitterEngine.getInstance(context);
|
||||
GlobalSettings settings = GlobalSettings.getInstance(context);
|
||||
sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss", Locale.GERMANY);
|
||||
sdf = settings.getDateFormatter();
|
||||
font = settings.getFontColor();
|
||||
highlight = settings.getHighlightColor();
|
||||
toggleImg = settings.loadImages();
|
||||
|
@ -8,8 +8,6 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.nuclearfog.twidda.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LogAdapter extends Adapter<LogAdapter.ItemHolder> {
|
||||
@ -28,7 +26,7 @@ public class LogAdapter extends Adapter<LogAdapter.ItemHolder> {
|
||||
@NonNull
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
@ -36,13 +34,14 @@ public class LogAdapter extends Adapter<LogAdapter.ItemHolder> {
|
||||
public void onBindViewHolder(@NonNull ItemHolder vh, int index) {
|
||||
vh.message.setText(messages.get(index));
|
||||
vh.message.setTextColor(0xffff0000);
|
||||
vh.message.setTextSize(12.0f);
|
||||
}
|
||||
|
||||
class ItemHolder extends RecyclerView.ViewHolder {
|
||||
public final TextView message;
|
||||
ItemHolder(View 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