code cleanup, bug fix

This commit is contained in:
nuclearfog 2020-05-27 22:11:13 +02:00
parent 734f0ff7ba
commit f5f214448c
No known key found for this signature in database
GPG Key ID: ED35E22099354A64
13 changed files with 46 additions and 42 deletions

View File

@ -62,7 +62,8 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
BACKGROUND, BACKGROUND,
FONTCOLOR, FONTCOLOR,
HIGHLIGHT, HIGHLIGHT,
POPUPCOLOR POPUPCOLOR,
NONE
} }
private GlobalSettings settings; private GlobalSettings settings;
@ -75,8 +76,8 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
private LocationAdapter locationAdapter; private LocationAdapter locationAdapter;
private View root, colorButton1_edge; private View root, colorButton1_edge;
private ColorMode mode; private ColorMode mode = ColorMode.NONE;
private int color; private int color = 0;
@Override @Override
protected void onCreate(@Nullable Bundle b) { protected void onCreate(@Nullable Bundle b) {

View File

@ -26,7 +26,8 @@ public class ListDetail extends AppCompatActivity implements OnTabSelectedListen
private FragmentAdapter adapter; private FragmentAdapter adapter;
private ViewPager pager; private ViewPager pager;
private int tabIndex;
private int tabIndex = 0;
@Override @Override
protected void onCreate(@Nullable Bundle b) { protected void onCreate(@Nullable Bundle b) {

View File

@ -36,7 +36,8 @@ public class LoginPage extends AppCompatActivity implements OnClickListener {
private Button btnLink, btnVeri; private Button btnLink, btnVeri;
private EditText pin; private EditText pin;
private View root; private View root;
private String link; private @Nullable
String link;
@Override @Override
protected void onCreate(@Nullable Bundle b) { protected void onCreate(@Nullable Bundle b) {

View File

@ -42,6 +42,7 @@ public class MainActivity extends AppCompatActivity implements OnTabSelectedList
private ViewPager pager; private ViewPager pager;
private View root; private View root;
private long homeId; private long homeId;
private int tabIndex = 0; private int tabIndex = 0;
static { static {

View File

@ -1,7 +1,6 @@
package org.nuclearfog.twidda.activity; package org.nuclearfog.twidda.activity;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Point;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.media.MediaPlayer.OnInfoListener; import android.media.MediaPlayer.OnInfoListener;
import android.media.MediaPlayer.OnPreparedListener; import android.media.MediaPlayer.OnPreparedListener;
@ -10,7 +9,6 @@ import android.os.AsyncTask.Status;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.view.Display;
import android.view.View; import android.view.View;
import android.widget.MediaController; import android.widget.MediaController;
import android.widget.ProgressBar; import android.widget.ProgressBar;
@ -68,7 +66,7 @@ public class MediaViewer extends AppCompatActivity implements OnImageClickListen
private ZoomView zoomImage; private ZoomView zoomImage;
private String[] link; private String[] link;
private int type; private int type;
private int width;
private int lastPos = 0; private int lastPos = 0;
@ -99,10 +97,6 @@ public class MediaViewer extends AppCompatActivity implements OnImageClickListen
imageWindow.setVisibility(VISIBLE); imageWindow.setVisibility(VISIBLE);
imageList.setLayoutManager(new LinearLayoutManager(this, HORIZONTAL, false)); imageList.setLayoutManager(new LinearLayoutManager(this, HORIZONTAL, false));
imageList.setAdapter(adapter); imageList.setAdapter(adapter);
Display d = getWindowManager().getDefaultDisplay();
Point size = new Point();
d.getSize(size);
width = size.x;
break; break;
case MEDIAVIEWER_ANGIF: case MEDIAVIEWER_ANGIF:
@ -246,9 +240,12 @@ public class MediaViewer extends AppCompatActivity implements OnImageClickListen
private void changeImage(Bitmap image) { private void changeImage(Bitmap image) {
int width = zoomImage.getMeasuredWidth();
if (width > 0 && image.getWidth() > width) {
float ratio = image.getWidth() / (float) width; float ratio = image.getWidth() / (float) width;
int destHeight = (int) (image.getHeight() / ratio); int destHeight = (int) (image.getHeight() / ratio);
image = Bitmap.createScaledBitmap(image, width, destHeight, false); image = Bitmap.createScaledBitmap(image, width, destHeight, false);
}
zoomImage.reset(); zoomImage.reset();
zoomImage.setImageBitmap(image); zoomImage.setImageBitmap(image);
} }

View File

@ -48,9 +48,10 @@ public class MessagePopup extends AppCompatActivity implements OnClickListener,
private static final int REQ_PERM_READ = 4; private static final int REQ_PERM_READ = 4;
private MessageUploader messageAsync; private MessageUploader messageAsync;
private EditText receiver, text; private EditText receiver, message;
private Dialog loadingCircle; private Dialog loadingCircle;
private String mediaPath = ""; private @Nullable
String mediaPath;
@Override @Override
@ -61,15 +62,15 @@ public class MessagePopup extends AppCompatActivity implements OnClickListener,
View send = findViewById(R.id.dm_send); View send = findViewById(R.id.dm_send);
View media = findViewById(R.id.dm_media); View media = findViewById(R.id.dm_media);
receiver = findViewById(R.id.dm_receiver); receiver = findViewById(R.id.dm_receiver);
text = findViewById(R.id.dm_text); message = findViewById(R.id.dm_text);
loadingCircle = new Dialog(this, R.style.LoadingDialog); loadingCircle = new Dialog(this, R.style.LoadingDialog);
View load = View.inflate(this, R.layout.item_load, null); View load = View.inflate(this, R.layout.item_load, null);
View cancelButton = load.findViewById(R.id.kill_button); View cancelButton = load.findViewById(R.id.kill_button);
Bundle param = getIntent().getExtras(); Bundle param = getIntent().getExtras();
if (param != null && param.containsKey(KEY_DM_PREFIX)) { if (param != null && param.containsKey(KEY_DM_PREFIX)) {
String addtion = param.getString(KEY_DM_PREFIX); String prefix = param.getString(KEY_DM_PREFIX);
receiver.append(addtion); receiver.append(prefix);
} }
GlobalSettings settings = GlobalSettings.getInstance(this); GlobalSettings settings = GlobalSettings.getInstance(this);
@ -89,7 +90,7 @@ public class MessagePopup extends AppCompatActivity implements OnClickListener,
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (text.getText().toString().isEmpty() && mediaPath.isEmpty()) { if (receiver.getText().length() == 0 && message.getText().length() == 0 && mediaPath == null) {
super.onBackPressed(); super.onBackPressed();
} else { } else {
Builder closeDialog = new Builder(this, R.style.ConfirmDialog); Builder closeDialog = new Builder(this, R.style.ConfirmDialog);
@ -142,8 +143,8 @@ public class MessagePopup extends AppCompatActivity implements OnClickListener,
switch (v.getId()) { switch (v.getId()) {
case R.id.dm_send: case R.id.dm_send:
String username = receiver.getText().toString(); String username = receiver.getText().toString();
String message = text.getText().toString(); String message = this.message.getText().toString();
if (!username.trim().isEmpty() && (!message.trim().isEmpty() || !mediaPath.isEmpty())) { if (!username.trim().isEmpty() && (!message.trim().isEmpty() || mediaPath != null)) {
MessageHolder messageHolder = new MessageHolder(username, message, mediaPath); MessageHolder messageHolder = new MessageHolder(username, message, mediaPath);
messageAsync = new MessageUploader(this, messageHolder); messageAsync = new MessageUploader(this, messageHolder);
messageAsync.execute(); messageAsync.execute();
@ -153,7 +154,7 @@ public class MessagePopup extends AppCompatActivity implements OnClickListener,
break; break;
case R.id.dm_media: case R.id.dm_media:
if (mediaPath.trim().isEmpty()) if (mediaPath == null)
getMedia(); getMedia();
else { else {
Intent image = new Intent(this, MediaViewer.class); Intent image = new Intent(this, MediaViewer.class);

View File

@ -62,7 +62,7 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener, Lo
NONE, NONE,
GIF, GIF,
IMAGE, IMAGE,
VIDEO, VIDEO
} }
private static final String[] PERM_STORAGE = {READ_EXTERNAL_STORAGE}; private static final String[] PERM_STORAGE = {READ_EXTERNAL_STORAGE};
@ -83,10 +83,9 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener, Lo
private Dialog loadingCircle; private Dialog loadingCircle;
private TextView imgCount; private TextView imgCount;
private EditText tweetText; private EditText tweetText;
private String addition = "";
private long inReplyId = 0;
private MediaType selectedFormat = MediaType.NONE; private MediaType selectedFormat = MediaType.NONE;
private long inReplyId = 0;
@Override @Override
protected void onCreate(@Nullable Bundle b) { protected void onCreate(@Nullable Bundle b) {
@ -112,7 +111,10 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener, Lo
Bundle param = getIntent().getExtras(); Bundle param = getIntent().getExtras();
if (param != null) { if (param != null) {
inReplyId = param.getLong(KEY_TWEETPOPUP_REPLYID, 0); inReplyId = param.getLong(KEY_TWEETPOPUP_REPLYID, 0);
addition = param.getString(KEY_TWEETPOPUP_PREFIX, "") + " "; if (param.containsKey(KEY_TWEETPOPUP_PREFIX)) {
String addition = param.getString(KEY_TWEETPOPUP_PREFIX) + " ";
tweetText.append(addition);
}
} }
loadingCircle.requestWindowFeature(FEATURE_NO_TITLE); loadingCircle.requestWindowFeature(FEATURE_NO_TITLE);
@ -120,7 +122,6 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener, Lo
loadingCircle.setContentView(load); loadingCircle.setContentView(load);
FontTool.setViewFontAndColor(settings, root); FontTool.setViewFontAndColor(settings, root);
root.setBackgroundColor(settings.getPopupColor()); root.setBackgroundColor(settings.getPopupColor());
tweetText.append(addition);
closeButton.setOnClickListener(this); closeButton.setOnClickListener(this);
tweetButton.setOnClickListener(this); tweetButton.setOnClickListener(this);
@ -363,7 +364,7 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener, Lo
* show confirmation dialog when closing edited tweet * show confirmation dialog when closing edited tweet
*/ */
private void showClosingMsg() { private void showClosingMsg() {
if (!addition.equals(tweetText.getText().toString()) || !mediaPath.isEmpty()) { if (tweetText.getText().length() > 0 || !mediaPath.isEmpty()) {
Builder closeDialog = new Builder(this, R.style.ConfirmDialog); Builder closeDialog = new Builder(this, R.style.ConfirmDialog);
closeDialog.setMessage(R.string.confirm_cancel_tweet); closeDialog.setMessage(R.string.confirm_cancel_tweet);
closeDialog.setNegativeButton(R.string.confirm_no, null); closeDialog.setNegativeButton(R.string.confirm_no, null);

View File

@ -48,14 +48,13 @@ public class TweetUploader extends AsyncTask<Void, Void, Boolean> {
protected Boolean doInBackground(Void[] v) { protected Boolean doInBackground(Void[] v) {
try { try {
mTwitter.uploadStatus(tweet); mTwitter.uploadStatus(tweet);
return true;
} catch (EngineException twException) { } catch (EngineException twException) {
this.twException = twException; this.twException = twException;
return false;
} catch (Exception exception) { } catch (Exception exception) {
exception.printStackTrace(); exception.printStackTrace();
return false;
} }
return true; return false;
} }

View File

@ -733,9 +733,8 @@ public class TwitterEngine {
try { try {
long id = twitter.showUser(messageHolder.getUsername()).getId(); long id = twitter.showUser(messageHolder.getUsername()).getId();
if (messageHolder.hasMedia()) { if (messageHolder.hasMedia()) {
UploadedMedia media = twitter.uploadMedia(new File(messageHolder.getMediaPath())); long[] mediaId = uploadImages(messageHolder.getMediaPath());
long mediaId = media.getMediaId(); twitter.sendDirectMessage(id, messageHolder.getMessage(), mediaId[0]);
twitter.sendDirectMessage(id, messageHolder.getMessage(), mediaId);
} else { } else {
twitter.sendDirectMessage(id, messageHolder.getMessage()); twitter.sendDirectMessage(id, messageHolder.getMessage());
} }

View File

@ -76,7 +76,7 @@ public abstract class ErrorHandler {
break; break;
case NO_MEDIA_FOUND: case NO_MEDIA_FOUND:
Toast.makeText(context, R.string.error_no_media_app, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.error_file_not_found, Toast.LENGTH_SHORT).show();
break; break;
case NO_LINK_DEFINED: case NO_LINK_DEFINED:

View File

@ -1,6 +1,7 @@
package org.nuclearfog.twidda.backend.items; package org.nuclearfog.twidda.backend.items;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/** /**
* Direct message holder class * Direct message holder class
@ -9,7 +10,7 @@ public class MessageHolder {
private final String username; private final String username;
private final String message; private final String message;
private final String mediaPath; private final String[] mediaPath;
/** /**
* Direct message constructor * Direct message constructor
@ -18,13 +19,13 @@ public class MessageHolder {
* @param message message text * @param message message text
* @param mediaPath local media path * @param mediaPath local media path
*/ */
public MessageHolder(String username, String message, String mediaPath) { public MessageHolder(String username, String message, @Nullable String mediaPath) {
if (username.startsWith("@")) if (username.startsWith("@"))
this.username = username; this.username = username;
else else
this.username = '@' + username; this.username = '@' + username;
this.message = message; this.message = message;
this.mediaPath = mediaPath; this.mediaPath = new String[]{mediaPath};
} }
/** /**
@ -47,7 +48,7 @@ public class MessageHolder {
* get local path of media * get local path of media
* @return media path * @return media path
*/ */
public String getMediaPath() { public String[] getMediaPath() {
return mediaPath; return mediaPath;
} }
@ -56,7 +57,7 @@ public class MessageHolder {
* @return if media is set * @return if media is set
*/ */
public boolean hasMedia() { public boolean hasMedia() {
return mediaPath != null && !mediaPath.isEmpty(); return mediaPath[0] != null;
} }
@NonNull @NonNull

View File

@ -146,4 +146,5 @@
<string name="settings_info_github">Github Seite:</string> <string name="settings_info_github">Github Seite:</string>
<string name="error_rate_limit">Zu viele Anfragen! Bitte 15 Minuten warten!</string> <string name="error_rate_limit">Zu viele Anfragen! Bitte 15 Minuten warten!</string>
<string name="info_cant_add_video">Video konnte nicht hinzugefügt werden!</string> <string name="info_cant_add_video">Video konnte nicht hinzugefügt werden!</string>
<string name="error_file_not_found">Datei nicht gefunden!</string>
</resources> </resources>

View File

@ -149,4 +149,5 @@
<string name="error_rate_limit">Too many requests! Please wait 15 minutes.</string> <string name="error_rate_limit">Too many requests! Please wait 15 minutes.</string>
<string name="info_cant_add_video">Can\'t add video!</string> <string name="info_cant_add_video">Can\'t add video!</string>
<string name="badge_twitter4j" translatable="false">Twitter4J Badge</string> <string name="badge_twitter4j" translatable="false">Twitter4J Badge</string>
<string name="error_file_not_found">File not found!</string>
</resources> </resources>