-Bug fix
This commit is contained in:
NudeDude 2018-12-02 13:01:38 +01:00
parent 1c1abd11d0
commit 2a2eef26bc
8 changed files with 53 additions and 78 deletions

View File

@ -9,7 +9,7 @@ android {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName '1.2.2'
versionName '1.3'
vectorDrawables.useSupportLibrary = true
}

View File

@ -33,11 +33,6 @@
android:host="*.twitter.com"
android:scheme="https" />
<data
android:host="*.twitter.com"
android:pathPattern="\\/.*?.*"
android:scheme="https" />
</intent-filter>
</activity>

View File

@ -112,8 +112,8 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
@Override
protected void onResume() {
super.onResume();
protected void onStart() {
super.onStart();
if (!settings.getLogin()) {
Intent i = new Intent(this, LoginPage.class);
startActivityForResult(i, LOGIN);
@ -146,14 +146,14 @@ public class MainActivity extends AppCompatActivity implements OnRefreshListener
@Override
protected void onPause() {
protected void onStop() {
if (home != null && home.getStatus() == RUNNING) {
home.cancel(true);
}
if (mBrowser != null && mBrowser.getStatus() == RUNNING) {
mBrowser.cancel(true);
}
super.onPause();
super.onStop();
}

View File

@ -15,10 +15,8 @@ import android.widget.Toast;
import org.nuclearfog.twidda.MainActivity;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.items.Tweet;
import org.nuclearfog.twidda.backend.items.TwitterUser;
import org.nuclearfog.twidda.database.DatabaseAdapter;
import org.nuclearfog.twidda.window.TweetDetail;
import org.nuclearfog.twidda.window.UserProfile;
import java.lang.ref.WeakReference;
import java.util.regex.Matcher;
@ -26,22 +24,15 @@ import java.util.regex.Pattern;
import twitter4j.TwitterException;
public class LinkBrowser extends AsyncTask<Uri, Void, Integer> {
private static final int NO_MATCH = 0;
private static final int GET_USER = 1;
private static final int GET_TWEET = 2;
private static final int FAILURE = 3;
public class LinkBrowser extends AsyncTask<Uri, Void, Void> {
private WeakReference<MainActivity> ui;
private TwitterEngine mTwitter;
private DatabaseAdapter mData;
private TwitterUser user;
private Tweet tweet;
private LayoutInflater inflater;
private Dialog popup;
private String errMsg = "";
private String errMsg;
public LinkBrowser(MainActivity context) {
ui = new WeakReference<>(context);
@ -82,78 +73,61 @@ public class LinkBrowser extends AsyncTask<Uri, Void, Integer> {
@Override
protected Integer doInBackground(Uri... links) {
protected Void doInBackground(Uri... links) {
try {
String path = links[0].getPath();
if (path != null) {
Pattern linkPattern = Pattern.compile("\\/@?[\\w_]+\\/status\\/\\d{1,20}");
Matcher linkMatch = linkPattern.matcher(path);
if (linkMatch.matches()) {
Pattern idPattern = Pattern.compile("\\d{1,20}");
Matcher idMatcher = idPattern.matcher(path);
Pattern pattern = Pattern.compile("[^\\/\\?]+");
Matcher matcher = pattern.matcher(path);
if (idMatcher.find()) {
int start = idMatcher.start();
int end = idMatcher.end();
String idString = path.substring(start, end);
long tweetId = Long.parseLong(idString);
if (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
if (!matcher.find()) {
String username = path.substring(start, end);
user = mTwitter.getUser(username);
mData.storeUser(user);
return GET_USER;
}
}
if (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
String id = path.substring(start, end);
long tweetId = Long.parseLong(id);
tweet = mData.getStatus(tweetId);
if (tweet == null)
tweet = mTwitter.getStatus(tweetId);
return GET_TWEET;
}
}
}
} catch (TwitterException err) {
errMsg = err.getErrorMessage();
return FAILURE;
} catch (Exception err) {
Log.e("LinkBrowser", err.getMessage());
return FAILURE;
}
return NO_MATCH;
return null;
}
@Override
protected void onPostExecute(Integer mode) {
protected void onPostExecute(Void mode) {
if (ui.get() == null) return;
popup.dismiss();
switch (mode) {
case GET_TWEET:
if (tweet != null) {
Intent tweetActivity = new Intent(ui.get(), TweetDetail.class);
tweetActivity.putExtra("username", tweet.getUser().getScreenname());
tweetActivity.putExtra("userID", tweet.getUser().getId());
tweetActivity.putExtra("tweetID", tweet.getId());
ui.get().startActivity(tweetActivity);
break;
case GET_USER:
Intent userActivity = new Intent(ui.get(), UserProfile.class);
userActivity.putExtra("username", user.getScreenname());
userActivity.putExtra("userID", user.getId());
ui.get().startActivity(userActivity);
break;
case FAILURE:
if (errMsg.isEmpty()) {
} else {
if (errMsg == null) {
Toast.makeText(ui.get(), R.string.site_load_failure, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ui.get(), errMsg, Toast.LENGTH_LONG).show();
}
break;
}
}
@Override
protected void onCancelled(Integer i) {
protected void onCancelled(Void v) {
popup.dismiss();
}
}

View File

@ -97,8 +97,8 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener,
}
protected void onResume() {
super.onResume();
protected void onStart() {
super.onStart();
if (mStat == null) {
TimelineAdapter answerAdapter = new TimelineAdapter(this);
answerAdapter.toggleImage(settings.loadImages());
@ -113,10 +113,10 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener,
@Override
protected void onPause() {
protected void onStop() {
if (mStat != null && mStat.getStatus() == RUNNING)
mStat.cancel(true);
super.onPause();
super.onStop();
}

View File

@ -102,8 +102,8 @@ public class UserProfile extends AppCompatActivity implements OnRefreshListener,
@Override
protected void onResume() {
super.onResume();
protected void onStart() {
super.onStart();
if (mProfile == null) {
TimelineAdapter homeTl = new TimelineAdapter(this);
homeTl.setColor(settings.getHighlightColor(), settings.getFontColor());
@ -124,10 +124,10 @@ public class UserProfile extends AppCompatActivity implements OnRefreshListener,
@Override
protected void onPause() {
protected void onStop() {
if (mProfile != null && mProfile.getStatus() == RUNNING)
mProfile.cancel(true);
super.onPause();
super.onStop();
}

View File

@ -38,8 +38,7 @@
android:id="@+id/img_preview"
android:layout_width="@dimen/tweet_button_size"
android:layout_height="@dimen/tweet_button_size"
android:layout_marginStart="@dimen/tweet_icon_margin"
android:layout_marginLeft="@dimen/tweet_icon_margin"
android:contentDescription="@string/image_preview"
android:visibility="invisible"
app:srcCompat="@drawable/preview" />
@ -49,6 +48,7 @@
android:layout_height="@dimen/tweet_button_size"
android:layout_marginStart="@dimen/tweet_icon_margin"
android:layout_marginLeft="@dimen/tweet_icon_margin"
android:contentDescription="@string/add_image"
app:srcCompat="@drawable/image" />
<ImageView
@ -57,6 +57,7 @@
android:layout_height="@dimen/tweet_button_size"
android:layout_marginStart="@dimen/tweet_icon_margin"
android:layout_marginLeft="@dimen/tweet_icon_margin"
android:contentDescription="@string/send_tweet"
app:srcCompat="@drawable/tweet" />
<ImageView
@ -65,6 +66,7 @@
android:layout_height="@dimen/tweet_button_size"
android:layout_marginStart="@dimen/tweet_icon_margin"
android:layout_marginLeft="@dimen/tweet_icon_margin"
android:contentDescription="@string/tweet_close"
app:srcCompat="@drawable/cross" />
</LinearLayout>

View File

@ -86,4 +86,8 @@
<string name="tweet_processing">processing..</string>
<string name="tweet_loading">loading..</string>
<string name="site_load_failure">error while loading site!</string>
<string name="image_preview">Image preview</string>
<string name="add_image">add new image</string>
<string name="send_tweet">send Tweet</string>
<string name="tweet_close">close tweet</string>
</resources>