major bugfixes

This commit is contained in:
NudeDude 2018-07-27 19:23:46 +02:00
parent e161613489
commit afaa4e02b0
11 changed files with 115 additions and 101 deletions

View File

@ -41,7 +41,7 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
private static final long IGNORE = 7;
private String screenName, username, description, location, follower, following;
private String /* bannerLink,*/ profileImage, link, dateString;
private String profileImage, link, dateString;
private TimelineRecycler homeTl, homeFav;
private WeakReference<UserProfile> ui;
private TwitterEngine mTwitter;
@ -54,7 +54,7 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
private boolean isFollowed = false;
private boolean isVerified = false;
private boolean isLocked = false;
private boolean muted = false;
private boolean blocked = false;
/**
* @param context Context to Activity
@ -91,55 +91,53 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
long id = 1L;
try {
isHome = homeId == userId;
if(!isHome && MODE != LOAD_DB)
if(!isHome && (MODE==ACTION_FOLLOW||MODE==ACTION_MUTE||MODE==GET_INFORMATION))
{
boolean connection[] = mTwitter.getConnection(userId);
isFollowing = connection[0];
isFollowed = connection[1];
muted = connection[2];
blocked = connection[2];
}
if(MODE == GET_INFORMATION || MODE == LOAD_DB)
{
TwitterUser user;
if(MODE == LOAD_DB) {
user = new DatabaseAdapter(ui.get()).getUser(userId);
if(user == null)
return IGNORE;
} else {
user = mTwitter.getUser(userId);
new DatabaseAdapter(ui.get()).storeUser(user);
}
screenName = user.screenname;
username = user.username;
description = user.bio;
location = user.location;
isVerified = user.isVerified;
isLocked = user.isLocked;
link = user.link;
follower = Integer.toString(user.follower);
following = Integer.toString(user.following);
// bannerLink = user.bannerImg;
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);
description = description.replace('\n', ' ');
TwitterUser user;
DatabaseAdapter database = new DatabaseAdapter(ui.get());
if(MODE == GET_INFORMATION) {
user = mTwitter.getUser(userId);
database.storeUser(user);
} else {
user = database.getUser(userId);
if(user == null)
return IGNORE;
}
else if(MODE == GET_TWEETS)
screenName = user.screenname;
username = user.username;
description = user.bio;
location = user.location;
isVerified = user.isVerified;
isLocked = user.isLocked;
link = user.link;
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);
description = description.replace('\n', ' ');
if(MODE == GET_TWEETS)
{
DatabaseAdapter tweetDb = new DatabaseAdapter(ui.get());
List<Tweet> tweets;
if(homeTl.getItemCount() > 0) {
id = homeTl.getItemId(0);
tweets = mTwitter.getUserTweets(userId,args[2],id);
tweetDb.storeUserTweets(tweets);
database.storeUserTweets(tweets);
tweets.addAll(homeTl.getData());
} else {
tweets = tweetDb.getUserTweets(userId);
if(tweets.size() == 0) {
tweets = database.getUserTweets(userId);
if(tweets.size() == 0 && !isLocked) {
tweets = mTwitter.getUserTweets(userId,args[2],id);
tweetDb.storeUserTweets(tweets);
database.storeUserTweets(tweets);
}
}
homeTl.setData(tweets);
@ -148,19 +146,18 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
}
else if(MODE == GET_FAVS)
{
DatabaseAdapter tweetDb = new DatabaseAdapter(ui.get());
List<Tweet> favorits;
if(homeFav.getItemCount() > 0) {
id = homeFav.getItemId(0);
favorits = mTwitter.getUserFavs(userId,args[2],id);
tweetDb.storeUserFavs(favorits,userId);
database.storeUserFavs(favorits,userId);
favorits.addAll(homeFav.getData());
} else {
favorits = tweetDb.getUserFavs(userId);
if(favorits.size() == 0) {
favorits = database.getUserFavs(userId);
if(favorits.size() == 0 && !isLocked) {
favorits = mTwitter.getUserFavs(userId,args[2],id);
tweetDb.storeUserFavs(favorits,userId);
database.storeUserFavs(favorits,userId);
}
}
homeFav.setData(favorits);
@ -169,11 +166,23 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
}
else if(MODE == ACTION_FOLLOW)
{
isFollowing = mTwitter.toggleFollow(userId);
if(isFollowing) {
mTwitter.followAction(userId,false);
isFollowing = false;
} else {
mTwitter.followAction(userId,true);
isFollowing = true;
}
}
else if(MODE == ACTION_MUTE)
{
muted = mTwitter.toggleBlock(userId);
if(blocked) {
mTwitter.blockAction(userId,false);
blocked = false;
} else {
mTwitter.blockAction(userId,true);
blocked = true;
}
}
} catch (TwitterException err) {
int errCode = err.getErrorCode();
@ -268,7 +277,7 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
}
else if(mode == ACTION_MUTE) {
String text;
if(muted)
if(blocked)
text = "gesperrt!";
else
text = "entsperrt!";
@ -282,7 +291,7 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
tweetsReload.setRefreshing(false);
favoritsReload.setRefreshing(false);
}
if(!isHome) {
if(!isHome && (mode==ACTION_FOLLOW||mode==ACTION_MUTE||mode==GET_INFORMATION)) {
Toolbar tool = connect.findViewById(R.id.profile_toolbar);
if(tool.getMenu().size() >= 2) {
MenuItem followIcon = tool.getMenu().getItem(1);
@ -294,12 +303,14 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
followIcon.setIcon(R.drawable.follow);
followIcon.setTitle("folgen");
}
if (muted) {
if (blocked) {
blockIcon.setIcon(R.drawable.block_enabled);
blockIcon.setTitle("entblocken");
followIcon.setVisible(false);
} else {
blockIcon.setIcon(R.drawable.block);
blockIcon.setTitle("block");
followIcon.setVisible(true);
}
}
}

View File

@ -56,7 +56,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
private String errorMessage = "";
private boolean retweeted, favorited, toggleImg, verified;
private boolean rtFlag = false;
private long tweetReplyID,tweetID, userID, retweeterID;
private long tweetReplyID,tweetID, userID, retweeterID, homeId;
private int rtCount, favCount;
private int highlight, font;
@ -68,6 +68,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
font = settings.getFontColor();
highlight = settings.getHighlightColor();
toggleImg = settings.loadImages();
homeId = settings.getUserId();
ui = new WeakReference<>((TweetDetail)c);
RecyclerView replyList = ui.get().findViewById(R.id.answer_list);
answerAdapter = (TimelineRecycler) replyList.getAdapter();
@ -99,6 +100,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
} else {
tweet = mTwitter.getStatus(tweetID);
}
if (tweet.embedded != null) {
retweeter = tweet.user.screenname;
retweeterID = tweet.user.userID;
@ -130,7 +132,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
rtCount++;
retweeted = true;
} else {
if(rtCount>0)
if(rtCount > 0)
rtCount--;
retweeted = false;
}
@ -141,9 +143,10 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
favCount++;
favorited = true;
} else {
if(rtCount>0)
if(favCount > 0)
favCount--;
favorited = false;
database.removeFavorite(tweetID,homeId);
}
}
else if(MODE == LOAD_REPLY) {
@ -162,7 +165,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
}
else if(MODE == DELETE) {
mTwitter.deleteTweet(tweetID);
new DatabaseAdapter(ui.get()).removeStatus(tweetID);
database.removeStatus(tweetID);
}
if(MODE == LOAD_TWEET || MODE == RETWEET || MODE == FAVORITE) {
if(database.containStatus(tweetID))

View File

@ -277,34 +277,30 @@ public class TwitterEngine {
/**
* Switch following User
* @param id Uder ID
* @return follow status
* @param userId User ID
* @param action using action
* @throws TwitterException if Access is unavailable
*/
public boolean toggleFollow(long id) throws TwitterException {
if(getConnection(id)[0]) {
twitter.destroyFriendship(id);
return false;
public void followAction(long userId, boolean action) throws TwitterException {
if(action) {
twitter.createFriendship(userId);
} else {
twitter.createFriendship(id);
return true;
twitter.destroyFriendship(userId);
}
}
/**
* Switch blocking User
* @param id User ID
* @return Block Status
* @param userId User ID
* @param action using action
* @throws TwitterException if Access is unavailable
*/
public boolean toggleBlock(long id) throws TwitterException {
if(getConnection(id)[2]){
twitter.destroyBlock(id);
return false;
public void blockAction(long userId, boolean action) throws TwitterException {
if(action){
twitter.createBlock(userId);
} else {
twitter.createBlock(id);
return true;
twitter.destroyBlock(userId);
}
}
@ -504,7 +500,7 @@ public class TwitterEngine {
try {
Status embedded = status.getRetweetedStatus();
if(embedded != null) {
Tweet retweet = getTweet(embedded, null);
Tweet retweet = getTweet(embedded,null);
Tweet tweet = getTweet(status, retweet);
result.add(tweet);
} else {

View File

@ -48,7 +48,7 @@ public class DatabaseAdapter {
for(int pos = 0; pos < fav.size(); pos++) {
Tweet tweet = fav.get(pos);
storeStatus(tweet,0,db);
ContentValues favTable = new ContentValues();
ContentValues favTable = new ContentValues();
favTable.put("tweetID", tweet.tweetID);
favTable.put("userID", ownerId);
db.insertWithOnConflict("favorit",null,favTable,CONFLICT_IGNORE);
@ -285,12 +285,18 @@ public class DatabaseAdapter {
* Lösche Tweet
* @param id Tweet ID
*/
public void removeStatus(final long id) {
public void removeStatus(long id) {
SQLiteDatabase db = dataHelper.getWritableDatabase();
db.delete("tweet", "tweetID="+id, null);
db.close();
}
public void removeFavorite(long tweetId,long ownerId) {
SQLiteDatabase db = dataHelper.getWritableDatabase();
db.delete("favorit","tweetID="+tweetId+" AND userID="+ownerId,null);
db.close();
}
/**
* Suche Tweet in Datenbank

View File

@ -0,0 +1,4 @@
<vector android:height="16dp" android:viewportHeight="20.0"
android:viewportWidth="20.0" android:width="16dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFF" android:pathData="M10,1.3l2.388,6.722H18.8l-5.232,3.948l1.871,6.928L10,14.744l-5.438,4.154l1.87,-6.928L1.199,8.022h6.412L10,1.3z"/>
</vector>

View File

@ -100,38 +100,28 @@
android:id="@+id/retweeter"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_marginEnd="5dp"
android:singleLine="true"
android:textSize="12sp" />
<Button
android:id="@+id/retweet"
android:layout_width="16dp"
android:layout_height="16dp"
android:background="@drawable/retweet" />
<TextView
android:id="@+id/retweet_number"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_weight="4"
android:drawablePadding="2dp"
android:drawableStart="@drawable/retweet"
android:singleLine="true"
android:textSize="12sp" />
<Button
android:id="@+id/favorite"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginStart="10dp"
android:background="@drawable/favorite" />
<TextView
android:id="@+id/favorite_number"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_weight="4"
android:drawablePadding="2dp"
android:drawableStart="@drawable/favorite_tweet"
android:singleLine="true"
android:textSize="12sp" />

View File

@ -27,8 +27,8 @@
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:background="@android:color/transparent"
android:drawableLeft="@drawable/key"
android:drawablePadding="2dp"
android:drawableStart="@drawable/key"
android:hint="@string/pin"
android:inputType="numberPassword"
android:singleLine="true" />

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -127,7 +126,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/following"
android:drawableStart="@drawable/following"
android:drawablePadding="2dp" />
<TextView
@ -135,7 +134,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/follower"
android:drawableStart="@drawable/follower"
android:drawablePadding="2dp" />
</LinearLayout>
@ -155,7 +154,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:drawableLeft="@drawable/location"
android:drawableStart="@drawable/location"
android:drawablePadding="2dp"
android:singleLine="true"
android:textSize="12sp"
@ -167,7 +166,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:autoLink="web"
android:drawableLeft="@drawable/link"
android:drawableStart="@drawable/link"
android:drawablePadding="2dp"
android:linksClickable="true"
android:singleLine="true"

View File

@ -98,7 +98,7 @@
android:id="@+id/load_dialog"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_height="wrap_content"
android:text="@string/load_factor" />
<CheckBox
@ -130,6 +130,12 @@
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:text="@string/woeid" />
<Button
android:id="@+id/woeid_clip"
android:layout_width="24dp"
@ -146,16 +152,8 @@
android:layout_weight="1"
android:background="@android:color/transparent"
android:inputType="number"
android:labelFor="@id/textView"
android:singleLine="true" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:text="@string/woeid" />
</LinearLayout>
<TextView

View File

@ -56,11 +56,17 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/profileimage_detail"
<android.support.v7.widget.CardView
android:layout_width="56dp"
android:layout_height="56dp"
android:contentDescription="@string/profile_image" />
app:cardCornerRadius="5dp">
<ImageView
android:id="@+id/profileimage_detail"
android:layout_width="56dp"
android:layout_height="56dp"
android:contentDescription="@string/profile_image" />
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"

View File

@ -42,6 +42,7 @@
<FrameLayout
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center"
android:layout_marginEnd="20dp">
<Button