added error check

updated library
renamed classes
This commit is contained in:
nuclearfog 2020-01-06 22:35:01 +01:00
parent 9cdfea8026
commit 2c00ea6514
No known key found for this signature in database
GPG Key ID: ED35E22099354A64
11 changed files with 58 additions and 21 deletions

View File

@ -44,5 +44,5 @@ dependencies {
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.QuadFlask:colorpicker:0.0.13'
implementation 'com.github.nuclearfog:ZoomView:1.0.2'
implementation 'com.github.nuclearfog:Tagger:d0ab932'
implementation 'com.github.nuclearfog:Tagger:01c1ae0'
}

View File

@ -107,7 +107,7 @@
android:theme="@style/HalfTransparency" />
<activity
android:name=".activity.ProfileSettings"
android:name=".activity.ProfileEditor"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" />

View File

@ -7,6 +7,7 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.util.Patterns;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -39,6 +40,7 @@ import org.nuclearfog.twidda.database.DatabaseAdapter;
import org.nuclearfog.twidda.database.GlobalSettings;
import java.util.List;
import java.util.regex.Matcher;
import static android.os.AsyncTask.Status.RUNNING;
import static android.view.View.GONE;
@ -343,6 +345,12 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
Editable editPass = proxyPass.getText();
if (editAddr != null && !editAddr.toString().isEmpty()) {
Matcher ipMatch = Patterns.IP_ADDRESS.matcher(editAddr);
if (!ipMatch.matches()) {
String errMsg = getString(R.string.error_wrong_ip);
proxyAddr.setError(errMsg);
success = false;
}
if (editPort == null || editPort.toString().isEmpty()) {
String errMsg = getString(R.string.error_empty_port);
proxyPort.setError(errMsg);

View File

@ -151,13 +151,19 @@ public class MessagePopup extends AppCompatActivity implements OnClickListener {
int check = checkSelfPermission(READ_EXTERNAL_STORAGE);
if (check == PERMISSION_GRANTED) {
Intent galleryIntent = new Intent(ACTION_PICK, EXTERNAL_CONTENT_URI);
if (galleryIntent.resolveActivity(getPackageManager()) != null)
startActivityForResult(galleryIntent, REQ_PERM_READ);
else
Toast.makeText(getApplicationContext(), R.string.error_no_media_app, LENGTH_SHORT).show();
} else {
requestPermissions(PERM_READ, REQ_PERM_READ);
}
} else {
Intent galleryIntent = new Intent(ACTION_PICK, EXTERNAL_CONTENT_URI);
if (galleryIntent.resolveActivity(getPackageManager()) != null)
startActivityForResult(galleryIntent, REQ_PERM_READ);
else
Toast.makeText(getApplicationContext(), R.string.error_no_media_app, LENGTH_SHORT).show();
}
}
}

View File

@ -25,7 +25,7 @@ import androidx.appcompat.widget.Toolbar;
import com.squareup.picasso.Picasso;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.ProfileEditor;
import org.nuclearfog.twidda.backend.ProfileUpdater;
import org.nuclearfog.twidda.backend.helper.FontTool;
import org.nuclearfog.twidda.backend.items.TwitterUser;
import org.nuclearfog.twidda.backend.items.UserHolder;
@ -43,14 +43,14 @@ import static org.nuclearfog.twidda.activity.MediaViewer.MediaType.IMAGE;
import static org.nuclearfog.twidda.activity.MediaViewer.MediaType.IMAGE_STORAGE;
public class ProfileSettings extends AppCompatActivity implements OnClickListener {
public class ProfileEditor extends AppCompatActivity implements OnClickListener {
private static final String[] PERM_READ = {READ_EXTERNAL_STORAGE};
private static final String[] MEDIA_MODE = {MediaStore.Images.Media.DATA};
private static final int REQ_PERM = 3;
private static final int REQ_PB = 4;
private ProfileEditor editorAsync;
private ProfileUpdater editorAsync;
private TwitterUser user;
private ImageView pb_image;
private EditText name, link, loc, bio;
@ -84,7 +84,7 @@ public class ProfileSettings extends AppCompatActivity implements OnClickListene
protected void onStart() {
super.onStart();
if (editorAsync == null) {
editorAsync = new ProfileEditor(this);
editorAsync = new ProfileUpdater(this);
editorAsync.execute();
}
}
@ -133,7 +133,7 @@ public class ProfileSettings extends AppCompatActivity implements OnClickListene
Toast.makeText(this, R.string.edit_empty_name, LENGTH_SHORT).show();
} else {
UserHolder userHolder = new UserHolder(username, userLink, userLoc, userBio, imgLink);
editorAsync = new ProfileEditor(this, userHolder);
editorAsync = new ProfileUpdater(this, userHolder);
editorAsync.execute();
}
}
@ -208,14 +208,20 @@ public class ProfileSettings extends AppCompatActivity implements OnClickListene
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int check = checkSelfPermission(READ_EXTERNAL_STORAGE);
if (check == PackageManager.PERMISSION_GRANTED) {
Intent i = new Intent(ACTION_PICK, EXTERNAL_CONTENT_URI);
startActivityForResult(i, REQ_PB);
Intent media = new Intent(ACTION_PICK, EXTERNAL_CONTENT_URI);
if (media.resolveActivity(getPackageManager()) != null)
startActivityForResult(media, REQ_PB);
else
Toast.makeText(getApplicationContext(), R.string.error_no_media_app, LENGTH_SHORT).show();
} else {
requestPermissions(PERM_READ, REQ_PERM);
}
} else {
Intent i = new Intent(ACTION_PICK, EXTERNAL_CONTENT_URI);
startActivityForResult(i, REQ_PB);
Intent media = new Intent(ACTION_PICK, EXTERNAL_CONTENT_URI);
if (media.resolveActivity(getPackageManager()) != null)
startActivityForResult(media, REQ_PB);
else
Toast.makeText(getApplicationContext(), R.string.error_no_media_app, LENGTH_SHORT).show();
}
}
}

View File

@ -326,11 +326,17 @@ public class TweetPopup extends AppCompatActivity implements OnClickListener, Lo
if (mode == Mode.NONE) {
Intent mediaIntent = new Intent(ACTION_PICK);
mediaIntent.setDataAndType(EXTERNAL_CONTENT_URI, TYPE_IMAGE + TYPE_VIDEO);
if (mediaIntent.resolveActivity(getPackageManager()) != null)
startActivityForResult(mediaIntent, PICK_MEDIA);
else
Toast.makeText(getApplicationContext(), R.string.error_no_media_app, LENGTH_SHORT).show();
} else if (mode == Mode.IMAGE) {
Intent imageIntent = new Intent(ACTION_PICK);
imageIntent.setDataAndType(EXTERNAL_CONTENT_URI, TYPE_IMAGE);
if (imageIntent.resolveActivity(getPackageManager()) != null)
startActivityForResult(imageIntent, PICK_MEDIA);
else
Toast.makeText(getApplicationContext(), R.string.error_no_media_app, LENGTH_SHORT).show();
}
}
}

View File

@ -267,7 +267,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
break;
case R.id.profile_settings:
Intent editProfile = new Intent(this, ProfileSettings.class);
Intent editProfile = new Intent(this, ProfileEditor.class);
startActivityForResult(editProfile, REQUEST_PROFILE_CHANGED);
break;
@ -372,6 +372,8 @@ public class UserProfile extends AppCompatActivity implements OnClickListener,
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
if (intent.resolveActivity(getPackageManager()) != null)
startActivity(intent);
else
Toast.makeText(this, R.string.connection_failed, LENGTH_SHORT).show();
}

View File

@ -10,7 +10,6 @@ import android.widget.Toast;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.activity.ProfileSettings;
import org.nuclearfog.twidda.backend.items.TwitterUser;
import org.nuclearfog.twidda.backend.items.UserHolder;
import org.nuclearfog.twidda.database.AppDatabase;
@ -21,9 +20,9 @@ import static android.widget.Toast.LENGTH_SHORT;
import static org.nuclearfog.twidda.activity.UserProfile.RETURN_PROFILE_CHANGED;
public class ProfileEditor extends AsyncTask<Void, Void, TwitterUser> {
public class ProfileUpdater extends AsyncTask<Void, Void, TwitterUser> {
private WeakReference<ProfileSettings> ui;
private WeakReference<org.nuclearfog.twidda.activity.ProfileEditor> ui;
private WeakReference<Dialog> popup;
private UserHolder userHolder;
private TwitterEngine mTwitter;
@ -36,7 +35,7 @@ public class ProfileEditor extends AsyncTask<Void, Void, TwitterUser> {
*
* @param context Activity context
*/
public ProfileEditor(ProfileSettings context) {
public ProfileUpdater(org.nuclearfog.twidda.activity.ProfileEditor context) {
ui = new WeakReference<>(context);
popup = new WeakReference<>(new Dialog(context));
mTwitter = TwitterEngine.getInstance(context);
@ -50,7 +49,7 @@ public class ProfileEditor extends AsyncTask<Void, Void, TwitterUser> {
* @param context Activity context
* @param userHolder user data
*/
public ProfileEditor(ProfileSettings context, UserHolder userHolder) {
public ProfileUpdater(org.nuclearfog.twidda.activity.ProfileEditor context, UserHolder userHolder) {
this(context);
this.userHolder = userHolder;
}

View File

@ -7,6 +7,7 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
@ -15,6 +16,7 @@ import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.activity.MessagePopup;
import org.nuclearfog.twidda.activity.SearchPage;
import org.nuclearfog.twidda.activity.UserProfile;
@ -27,6 +29,7 @@ import org.nuclearfog.twidda.database.GlobalSettings;
import static android.os.AsyncTask.Status.FINISHED;
import static android.os.AsyncTask.Status.RUNNING;
import static android.widget.Toast.LENGTH_SHORT;
import static org.nuclearfog.twidda.activity.MessagePopup.KEY_DM_PREFIX;
import static org.nuclearfog.twidda.activity.SearchPage.KEY_SEARCH_QUERY;
import static org.nuclearfog.twidda.activity.UserProfile.KEY_PROFILE_ID;
@ -97,6 +100,8 @@ public class MessageFragment extends Fragment implements OnRefreshListener, OnIt
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
if (intent.resolveActivity(getContext().getPackageManager()) != null)
startActivity(intent);
else
Toast.makeText(getContext(), R.string.connection_failed, LENGTH_SHORT).show();
}
}

View File

@ -139,4 +139,7 @@
<string name="edit_location_hint">Standortnamen eingeben</string>
<string name="settins_font">Schriftart</string>
<string name="page_profile_edior">Profil bearbeiten</string>
<string name="error_no_card_app">Keine Karten App gefunden!</string>
<string name="error_no_media_app">Keine Galerie App gefunden!</string>
<string name="error_wrong_ip">Falsche IP Adresse!</string>
</resources>

View File

@ -141,4 +141,6 @@
<string name="settins_font">Font style</string>
<string name="page_profile_edior">Edit profile</string>
<string name="error_no_card_app">No card app installed!</string>
<string name="error_no_media_app">No media app found!</string>
<string name="error_wrong_ip">wrong IP address!</string>
</resources>