mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 09:49:21 +02:00
fix building
This commit is contained in:
parent
2ca581495e
commit
fee58e6eac
415 changed files with 122 additions and 108 deletions
102
src/main/java/org/thoughtcrime/securesms/LocalHelpActivity.java
Normal file
102
src/main/java/org/thoughtcrime/securesms/LocalHelpActivity.java
Normal file
|
@ -0,0 +1,102 @@
|
|||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LocalHelpActivity extends WebViewActivity
|
||||
{
|
||||
public static final String SECTION_EXTRA = "section_extra";
|
||||
|
||||
@Override
|
||||
protected boolean allowInLockedMode() { return true; }
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle state, boolean ready) {
|
||||
super.onCreate(state, ready);
|
||||
setForceDark();
|
||||
getSupportActionBar().setTitle(getString(R.string.menu_help));
|
||||
|
||||
String section = getIntent().getStringExtra(SECTION_EXTRA);
|
||||
String helpPath = "help/LANG/help.html";
|
||||
String helpLang = "en";
|
||||
try {
|
||||
Locale locale = dynamicLanguage.getCurrentLocale();
|
||||
String appLang = locale.getLanguage();
|
||||
String appCountry = locale.getCountry();
|
||||
if (assetExists(helpPath.replace("LANG", appLang))) {
|
||||
helpLang = appLang;
|
||||
} else if (assetExists(helpPath.replace("LANG", appLang+"_"+appCountry))) {
|
||||
helpLang = appLang+"_"+appCountry;
|
||||
} else {
|
||||
appLang = appLang.substring(0, 2);
|
||||
if (assetExists(helpPath.replace("LANG", appLang))) {
|
||||
helpLang = appLang;
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
webView.loadUrl("file:///android_asset/" + helpPath.replace("LANG", helpLang) + (section!=null? section : ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
this.getMenuInflater().inflate(R.menu.local_help, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
super.onOptionsItemSelected(item);
|
||||
switch (item.getItemId()) {
|
||||
case R.id.log_scroll_up:
|
||||
webView.scrollTo(0, 0);
|
||||
return true;
|
||||
case R.id.learn_more:
|
||||
openOnlineUrl("https://delta.chat");
|
||||
return true;
|
||||
case R.id.privacy_policy:
|
||||
openOnlineUrl("https://delta.chat/gdpr");
|
||||
return true;
|
||||
case R.id.contribute:
|
||||
openOnlineUrl("https://github.com/deltachat/deltachat-android");
|
||||
return true;
|
||||
case R.id.report_issue:
|
||||
openOnlineUrl("https://github.com/deltachat/deltachat-android/issues");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (webView.canGoBack()) {
|
||||
webView.goBack();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean assetExists(String fileName) {
|
||||
// test using AssetManager.open();
|
||||
// AssetManager.list() is unreliable eg. on my Android 7 Moto G
|
||||
// and also reported to be pretty slow.
|
||||
boolean exists = false;
|
||||
try {
|
||||
AssetManager assetManager = getResources().getAssets();
|
||||
InputStream is = assetManager.open(fileName);
|
||||
exists = true;
|
||||
is.close();
|
||||
} catch(Exception e) {
|
||||
; // a non-existent asset is no error, the function's purpose is to check exactly that.
|
||||
}
|
||||
return exists;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue