version upgrade, added API key info

Signed-off-by: nuclearfog <hatespirit666@gmail.com>
This commit is contained in:
nuclearfog 2021-11-11 12:18:38 +01:00
parent dec6c2d20c
commit 1711058aca
No known key found for this signature in database
GPG Key ID: AA0271FBE406DB98
5 changed files with 28 additions and 5 deletions

View File

@ -12,8 +12,8 @@ android {
applicationId 'org.nuclearfog.twidda'
minSdkVersion 16
targetSdkVersion 31
versionCode 48
versionName '1.10.3'
versionCode 49
versionName '1.10.4'
// limiting language support for smaller APK size
resConfigs 'en', 'de-rDE', 'zh-rCN'
vectorDrawables.useSupportLibrary true

View File

@ -71,7 +71,7 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
private FontAdapter fontAdapter;
private Dialog connectDialog, databaseDialog, logoutDialog, color_dialog_selector, appInfo, license;
private View root, hqImageText, enableAuthTxt;
private View root, hqImageText, enableAuthTxt, api_info;
private EditText proxyAddr, proxyPort, proxyUser, proxyPass, api_key1, api_key2;
private SwitchButton enableProxy, enableAuth, hqImage, enableAPI;
private Spinner locationSpinner;
@ -117,6 +117,7 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
Spinner fontSpinner = findViewById(R.id.spinner_font);
enableProxy = findViewById(R.id.settings_enable_proxy);
enableAuth = findViewById(R.id.settings_enable_auth);
api_info = findViewById(R.id.settings_api_info);
hqImage = findViewById(R.id.settings_image_hq);
enableAPI = findViewById(R.id.settings_set_custom_keys);
locationSpinner = findViewById(R.id.spinner_woeid);
@ -186,6 +187,7 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
if (!settings.isCustomApiSet()) {
api_key1.setVisibility(GONE);
api_key2.setVisibility(GONE);
api_info.setVisibility(GONE);
}
toggleImg.setCheckedImmediately(settings.imagesEnabled());
toggleAns.setCheckedImmediately(settings.replyLoadingEnabled());
@ -514,9 +516,11 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
if (checked) {
api_key1.setVisibility(VISIBLE);
api_key2.setVisibility(VISIBLE);
api_info.setVisibility(VISIBLE);
} else {
api_key1.setVisibility(GONE);
api_key2.setVisibility(GONE);
api_info.setVisibility(GONE);
}
}
}
@ -618,18 +622,22 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
}
/**
* check proxy settings and save them if they are correct
* check app settings if they are correct and save them
* wrong settings will be skipped
*
* @return true if settings are saved successfully
*/
private boolean saveConnectionSettings() {
boolean checkPassed = true;
// check if proxy settings are correct
if (enableProxy.isChecked()) {
checkPassed = proxyAddr.length() > 0 && proxyPort.length() > 0;
// check IP address
if (checkPassed) {
Matcher ipMatch = Patterns.IP_ADDRESS.matcher(proxyAddr.getText());
checkPassed = ipMatch.matches();
}
// check Port number
if (checkPassed) {
int port = 0;
String portStr = proxyPort.getText().toString();
@ -638,9 +646,11 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
}
checkPassed = port > 0 && port < 65536;
}
// check user login
if (enableAuth.isChecked() && checkPassed) {
checkPassed = proxyUser.length() > 0 && proxyPass.length() > 0;
}
// save settings if correct
if (checkPassed) {
String proxyAddrStr = proxyAddr.getText().toString();
String proxyPortStr = proxyPort.getText().toString();
@ -653,6 +663,7 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
} else {
settings.clearProxyServer();
}
// check if API-keys are correct set
if (enableAPI.isChecked()) {
if (api_key1.length() > 0 && api_key2.length() > 0) {
String key1 = api_key1.getText().toString();

View File

@ -678,7 +678,7 @@
android:singleLine="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/settings_set_custom_keys"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/settings_api_info"
app:layout_constraintEnd_toStartOf="@id/settings_custom_key2"
app:layout_constraintHorizontal_weight="1"
style="@style/TextInput" />
@ -698,6 +698,16 @@
app:layout_constraintHorizontal_weight="1"
style="@style/TextInput" />
<TextView
android:id="@+id/settings_api_info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/settings_api_info"
app:layout_constraintStart_toStartOf="@id/settings_custom_key1"
app:layout_constraintTop_toBottomOf="@id/settings_custom_key1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/settings_custom_key2" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

View File

@ -217,4 +217,5 @@
<string name="info_permission_read">Leserechte werden benötigt um Bilder und Videos einzufügen.</string>
<string name="info_permission_location">Standortinformationen werden ausschließlich für Tweets verwendet.</string>
<string name="error_result_cancelled">Fehler, Anfrage wurde abgebrochen!</string>
<string name="settings_api_info">• Eine Änderung der API Schlüssel erfordert erneutes einloggen</string>
</resources>

View File

@ -21,6 +21,7 @@
<string name="settings_button_popup">Popup</string>
<string name="settings_color_card">Card color</string>
<string name="settings_icon_color">Icon color</string>
<string name="settings_api_info">• changing API Keys requires re-login</string>
<string name="highlight">Highlight</string>
<string name="settings_list_size">List size</string>
<string name="confirm_retry_button">retry</string>