mirror of
https://github.com/gsantner/dandelion
synced 2025-12-15 00:31:11 +01:00
Merge
This commit is contained in:
commit
c6e3a60411
94 changed files with 1144 additions and 253 deletions
|
|
@ -84,6 +84,7 @@ import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
|
|||
import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
|
||||
import com.github.dfa.diaspora_android.ui.CustomWebViewClient;
|
||||
import com.github.dfa.diaspora_android.util.Helpers;
|
||||
import com.github.dfa.diaspora_android.util.WebHelper;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
|
|
@ -114,14 +115,12 @@ public class MainActivity extends AppCompatActivity
|
|||
public static final String ACTION_CHANGE_ACCOUNT = "com.github.dfa.diaspora_android.MainActivity.change_account";
|
||||
public static final String ACTION_CLEAR_CACHE = "com.github.dfa.diaspora_android.MainActivity.clear_cache";
|
||||
public static final String ACTION_UPDATE_TITLE_FROM_URL = "com.github.dfa.diaspora_android.MainActivity.set_title";
|
||||
public static final String ACTION_RELOAD_ACTIVITY = "com.github.dfa.diaspora_android.MainActivity.reload_activity";
|
||||
public static final String URL_MESSAGE = "URL_MESSAGE";
|
||||
public static final String EXTRA_URL = "com.github.dfa.diaspora_android.extra_url";
|
||||
|
||||
private App app;
|
||||
private String podDomain;
|
||||
private Menu menu;
|
||||
private int notificationCount = 0;
|
||||
private int conversationCount = 0;
|
||||
private ValueCallback<Uri[]> mFilePathCallback;
|
||||
private String mCameraPhotoPath;
|
||||
private WebSettings webSettings;
|
||||
|
|
@ -219,7 +218,7 @@ public class MainActivity extends AppCompatActivity
|
|||
.setAction(android.R.string.yes, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.loadUrl("https://" + podDomain + "/notifications");
|
||||
} else {
|
||||
Snackbar.make(contentLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
||||
|
|
@ -236,7 +235,7 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
String url = "https://" + podDomain;
|
||||
if (savedInstanceState == null) {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.loadData("", "text/html", null);
|
||||
webView.loadUrl(url);
|
||||
} else {
|
||||
|
|
@ -291,7 +290,6 @@ public class MainActivity extends AppCompatActivity
|
|||
webViewClient = new CustomWebViewClient(app, webView);
|
||||
webView.setWebViewClient(webViewClient);
|
||||
|
||||
|
||||
/*
|
||||
* WebChromeClient
|
||||
*/
|
||||
|
|
@ -301,19 +299,15 @@ public class MainActivity extends AppCompatActivity
|
|||
progressBar.setProgress(progress);
|
||||
|
||||
if (progress > 0 && progress <= 60) {
|
||||
Helpers.getNotificationCount(wv);
|
||||
Helpers.getUserProfile(wv);
|
||||
WebHelper.getUserProfile(wv);
|
||||
WebHelper.optimizeMobileSiteLayout(wv);
|
||||
}
|
||||
|
||||
if (progress > 60) {
|
||||
Helpers.applyDiasporaMobileSiteChanges(wv);
|
||||
WebHelper.optimizeMobileSiteLayout(wv);
|
||||
}
|
||||
|
||||
if (progress == 100) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
} else {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
progressBar.setVisibility(progress == 100 ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -394,6 +388,10 @@ public class MainActivity extends AppCompatActivity
|
|||
app.getAvatarImageLoader().startImageDownload(navheaderImage, appSettings.getAvatarUrl());
|
||||
}
|
||||
}
|
||||
|
||||
Menu navMenu = navView.getMenu();
|
||||
navMenu.findItem(R.id.nav_exit).setVisible(appSettings.isShowExitButtonInNavAlso());
|
||||
|
||||
}
|
||||
|
||||
@OnClick(R.id.toolbar)
|
||||
|
|
@ -440,6 +438,9 @@ public class MainActivity extends AppCompatActivity
|
|||
Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true);
|
||||
} else if (ACTION_CLEAR_CACHE.equals(action)) {
|
||||
webView.clearCache(true);
|
||||
} else if (ACTION_RELOAD_ACTIVITY.equals(action)) {
|
||||
recreate();
|
||||
return;
|
||||
} else if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||
switch (type) {
|
||||
case "text/plain":
|
||||
|
|
@ -515,9 +516,11 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
if (webView.canGoBack()) {
|
||||
webView.goBack();
|
||||
} else {
|
||||
if (!snackbarExitApp.isShown())
|
||||
snackbarExitApp.show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!snackbarExitApp.isShown()) {
|
||||
snackbarExitApp.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -578,20 +581,19 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
this.menu = menu;
|
||||
MenuItem itemNotification = menu.findItem(R.id.action_notifications);
|
||||
if (itemNotification != null) {
|
||||
if (notificationCount > 0) {
|
||||
itemNotification.setIcon(R.drawable.ic_bell_ring_white_24dp);
|
||||
if (podUserProfile.getNotificationCount() > 0) {
|
||||
itemNotification.setIcon(R.drawable.ic_notifications_colored_48px);
|
||||
} else {
|
||||
itemNotification.setIcon(R.drawable.ic_bell_outline_white_24dp);
|
||||
itemNotification.setIcon(R.drawable.ic_notifications_white_48px);
|
||||
}
|
||||
|
||||
MenuItem itemConversation = menu.findItem(R.id.action_conversations);
|
||||
if (conversationCount > 0) {
|
||||
itemConversation.setIcon(R.drawable.ic_message_text_white_24dp);
|
||||
if (podUserProfile.getUnreadMessagesCount() > 0) {
|
||||
itemConversation.setIcon(R.drawable.ic_email_colored_48px);
|
||||
} else {
|
||||
itemConversation.setIcon(R.drawable.ic_message_text_outline_white_24dp);
|
||||
itemConversation.setIcon(R.drawable.ic_mail_white_48px);
|
||||
}
|
||||
}
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
|
|
@ -601,7 +603,7 @@ public class MainActivity extends AppCompatActivity
|
|||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_notifications: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.loadUrl("https://" + podDomain + "/notifications");
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -611,7 +613,7 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
case R.id.action_conversations: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.loadUrl("https://" + podDomain + "/conversations");
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -621,7 +623,7 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
case R.id.action_reload: {
|
||||
if(Helpers.isOnline(MainActivity.this)) {
|
||||
if(WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.reload();
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -642,7 +644,7 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
case R.id.action_compose: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.loadUrl("https://" + podDomain + "/status_messages/new");
|
||||
} else {
|
||||
snackbarNoInternet.show();
|
||||
|
|
@ -678,7 +680,7 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
case R.id.action_search: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
|
|
@ -746,6 +748,7 @@ public class MainActivity extends AppCompatActivity
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private boolean makeScreenshotOfWebView(boolean hasToShareScreenshot) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= 23) {
|
||||
int hasWRITE_EXTERNAL_STORAGE = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
|
|
@ -801,7 +804,7 @@ public class MainActivity extends AppCompatActivity
|
|||
if (bitmapWriter != null) {
|
||||
try {
|
||||
bitmapWriter.close();
|
||||
} catch (IOException _ignored) {/* Nothing */}
|
||||
} catch (IOException _ignSaveored) {/* Nothing */}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -836,12 +839,13 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
void handleSendText(Intent intent) {
|
||||
webView.loadUrl("https://"+podDomain+"/status_messages/new");
|
||||
String content = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
String content = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_TEXT));
|
||||
if(appSettings.isAppendSharedViaApp()) {
|
||||
//TODO: Make \n work
|
||||
content = content + " \n" +getString(R.string.shared_by_diaspora_android);
|
||||
// = \n
|
||||
content = content + "\n\n" + getString(R.string.shared_by_diaspora_android);
|
||||
}
|
||||
final String sharedText = content;
|
||||
|
||||
final String sharedText = WebHelper.escapeHtmlText(content);
|
||||
if (sharedText != null) {
|
||||
webView.setWebViewClient(new WebViewClient() {
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
|
|
@ -868,20 +872,24 @@ public class MainActivity extends AppCompatActivity
|
|||
*/
|
||||
void handleSendSubject(Intent intent) {
|
||||
webView.loadUrl("https://"+podDomain+"/status_messages/new");
|
||||
String content = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
final String sharedSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
||||
String content = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_TEXT));
|
||||
String subject = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_SUBJECT));
|
||||
|
||||
if (appSettings.isAppendSharedViaApp()) {
|
||||
//TODO: Make \n work
|
||||
content = content + " \n" + getString(R.string.shared_by_diaspora_android);
|
||||
// = \n
|
||||
content = content + "\n\n" + getString(R.string.shared_by_diaspora_android);
|
||||
}
|
||||
final String sharedText = content;
|
||||
if (sharedSubject != null) {
|
||||
|
||||
final String sharedSubject = WebHelper.escapeHtmlText(subject);
|
||||
final String sharedContent = WebHelper.escapeHtmlText(content);
|
||||
|
||||
if (subject != null) {
|
||||
webView.setWebViewClient(new WebViewClient() {
|
||||
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
webView.loadUrl("javascript:(function() { " +
|
||||
"document.getElementsByTagName('textarea')[0].style.height='110px'; " +
|
||||
"document.getElementsByTagName('textarea')[0].innerHTML = '**" + sharedSubject + "** " + sharedText + "'; " +
|
||||
"document.getElementsByTagName('textarea')[0].innerHTML = '**" + sharedSubject + "** " + sharedContent + "'; " +
|
||||
" if(document.getElementById(\"main_nav\")) {" +
|
||||
" document.getElementById(\"main_nav\").parentNode.removeChild(" +
|
||||
" document.getElementById(\"main_nav\"));" +
|
||||
|
|
@ -908,76 +916,34 @@ public class MainActivity extends AppCompatActivity
|
|||
// TODO: Move from Javascript interface
|
||||
@Override
|
||||
public void onNotificationCountChanged(int notificationCount) {
|
||||
// Count saved in PodUserProfile
|
||||
invalidateOptionsMenu();
|
||||
|
||||
if (notificationCount > 0 && !snackbarNewNotification.isShown()
|
||||
&& !webView.getUrl().equals("https://" + podDomain + "/notifications")) {
|
||||
snackbarNewNotification.show();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Move from Javascript interface
|
||||
@Override
|
||||
public void onUnreadMessageCountChanged(int unreadMessageCount) {
|
||||
// Count saved in PodUserProfile
|
||||
invalidateOptionsMenu();
|
||||
|
||||
if (unreadMessageCount > 0 && !snackbarNewNotification.isShown()
|
||||
&& !webView.getUrl().equals("https://" + podDomain + "/notifications")) {
|
||||
snackbarNewNotification.show();
|
||||
}
|
||||
}
|
||||
|
||||
private class JavaScriptInterface {
|
||||
@JavascriptInterface
|
||||
public void setNotificationCount(final String webMessage) {
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
notificationCount = Integer.valueOf(webMessage);
|
||||
|
||||
MenuItem item = menu.findItem(R.id.action_notifications);
|
||||
|
||||
if (item != null) {
|
||||
if (notificationCount > 0) {
|
||||
item.setIcon(R.drawable.ic_bell_ring_white_24dp);
|
||||
if (!snackbarNewNotification.isShown() && !webView.getUrl().equals("https://" + podDomain + "/notifications"))
|
||||
snackbarNewNotification.show();
|
||||
} else {
|
||||
item.setIcon(R.drawable.ic_bell_outline_white_24dp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void setUserProfile(final String webMessage) throws JSONException {
|
||||
if (podUserProfile.isRefreshNeeded()) {
|
||||
podUserProfile.parseJson(webMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void setConversationCount(final String webMessage) {
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
conversationCount = Integer.valueOf(webMessage);
|
||||
|
||||
MenuItem item = menu.findItem(R.id.action_conversations);
|
||||
|
||||
if (item != null) {
|
||||
if (conversationCount > 0) {
|
||||
item.setIcon(R.drawable.ic_message_text_white_24dp);
|
||||
if (!snackbarNewNotification.isShown() && !webView.getUrl().equals("https://" + podDomain + "/notifications"))
|
||||
snackbarNewNotification.show();
|
||||
} else {
|
||||
item.setIcon(R.drawable.ic_message_text_outline_white_24dp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("StatementWithEmptyBody")
|
||||
|
|
@ -986,7 +952,7 @@ public class MainActivity extends AppCompatActivity
|
|||
// Handle navigation view item clicks here.
|
||||
switch (item.getItemId()) {
|
||||
case R.id.nav_stream: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.loadUrl("https://" + podDomain + "/stream");
|
||||
} else {
|
||||
snackbarNoInternet.show();
|
||||
|
|
@ -995,7 +961,7 @@ public class MainActivity extends AppCompatActivity
|
|||
break;
|
||||
|
||||
case R.id.nav_profile: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.loadUrl("https://" + podDomain + "/people/" + appSettings.getProfileId());
|
||||
} else {
|
||||
snackbarNoInternet.show();
|
||||
|
|
@ -1004,9 +970,9 @@ public class MainActivity extends AppCompatActivity
|
|||
break;
|
||||
|
||||
case R.id.nav_followed_tags: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
// webView.loadUrl("https://" + podDomain + "/followed_tags");
|
||||
Helpers.showFollowedTagsList(webView, app);
|
||||
WebHelper.showFollowedTagsList(webView, app);
|
||||
setTitle(R.string.nav_followed_tags);
|
||||
} else {
|
||||
snackbarNoInternet.show();
|
||||
|
|
@ -1015,9 +981,9 @@ public class MainActivity extends AppCompatActivity
|
|||
break;
|
||||
|
||||
case R.id.nav_aspects: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
// webView.loadUrl("https://" + podDomain + "/aspects");
|
||||
Helpers.showAspectList(webView, app);
|
||||
WebHelper.showAspectList(webView, app);
|
||||
setTitle(R.string.aspects);
|
||||
} else {
|
||||
snackbarNoInternet.show();
|
||||
|
|
@ -1026,7 +992,7 @@ public class MainActivity extends AppCompatActivity
|
|||
break;
|
||||
|
||||
case R.id.nav_activities: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.loadUrl("https://" + podDomain + "/activity");
|
||||
} else {
|
||||
snackbarNoInternet.show();
|
||||
|
|
@ -1035,7 +1001,7 @@ public class MainActivity extends AppCompatActivity
|
|||
break;
|
||||
|
||||
case R.id.nav_liked: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.loadUrl("https://" + podDomain + "/liked");
|
||||
} else {
|
||||
snackbarNoInternet.show();
|
||||
|
|
@ -1044,7 +1010,7 @@ public class MainActivity extends AppCompatActivity
|
|||
break;
|
||||
|
||||
case R.id.nav_commented: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.loadUrl("https://" + podDomain + "/commented");
|
||||
} else {
|
||||
snackbarNoInternet.show();
|
||||
|
|
@ -1053,22 +1019,29 @@ public class MainActivity extends AppCompatActivity
|
|||
break;
|
||||
|
||||
case R.id.nav_mentions: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.loadUrl("https://" + podDomain + "/mentions");
|
||||
} else {
|
||||
snackbarNoInternet.show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.nav_public: {
|
||||
if (Helpers.isOnline(MainActivity.this)) {
|
||||
if (WebHelper.isOnline(MainActivity.this)) {
|
||||
webView.loadUrl("https://" + podDomain + "/public");
|
||||
} else {
|
||||
snackbarNoInternet.show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case R.id.nav_exit: {
|
||||
moveTaskToBack(true);
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.nav_settings_app: {
|
||||
startActivity(new Intent(this, SettingsActivity.class));
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ import com.github.dfa.diaspora_android.App;
|
|||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.task.GetPodsService;
|
||||
import com.github.dfa.diaspora_android.util.Helpers;
|
||||
import com.github.dfa.diaspora_android.util.WebHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
@ -80,7 +81,7 @@ public class PodSelectionActivity extends AppCompatActivity {
|
|||
setListedPods(app.getSettings().getPreviousPodlist());
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(podListReceiver, new IntentFilter(GetPodsService.MESSAGE_PODS_RECEIVED));
|
||||
|
||||
if (!Helpers.isOnline(PodSelectionActivity.this)) {
|
||||
if (!WebHelper.isOnline(PodSelectionActivity.this)) {
|
||||
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
|
@ -164,7 +165,7 @@ public class PodSelectionActivity extends AppCompatActivity {
|
|||
Linkify.addLinks(dialogMessage, Linkify.ALL);
|
||||
|
||||
// Check if online
|
||||
if (!Helpers.isOnline(PodSelectionActivity.this)) {
|
||||
if (!WebHelper.isOnline(PodSelectionActivity.this)) {
|
||||
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
|
@ -232,7 +233,7 @@ public class PodSelectionActivity extends AppCompatActivity {
|
|||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_reload: {
|
||||
if (Helpers.isOnline(PodSelectionActivity.this)) {
|
||||
if (WebHelper.isOnline(PodSelectionActivity.this)) {
|
||||
Intent i = new Intent(PodSelectionActivity.this, GetPodsService.class);
|
||||
startService(i);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import com.github.dfa.diaspora_android.R;
|
|||
public class SettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private SharedPreferences sharedPreferences;
|
||||
private boolean activityRestartRequired = false;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -124,6 +125,12 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
|||
intent.setAction(MainActivity.ACTION_CLEAR_CACHE);
|
||||
break;
|
||||
}
|
||||
case R.string.pref_title__show_exit_button_in_nav_also:
|
||||
case R.string.pref_title__intellihide_toolbars: {
|
||||
activityRestartRequired = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
default: {
|
||||
intent = null;
|
||||
break;
|
||||
|
|
@ -136,4 +143,14 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
|||
}
|
||||
return super.onPreferenceTreeClick(screen, preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
if (activityRestartRequired){
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.setAction(MainActivity.ACTION_RELOAD_ACTIVITY);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import android.widget.ImageView;
|
|||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.util.Helpers;
|
||||
import com.github.dfa.diaspora_android.util.WebHelper;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
|
|
|||
|
|
@ -87,6 +87,10 @@ public class AppSettings {
|
|||
return pref.getBoolean(context.getString(ressourceId), defaultValue);
|
||||
}
|
||||
|
||||
private int getInt(SharedPreferences pref, int ressourceId, int defaultValue) {
|
||||
return pref.getInt(context.getString(ressourceId), defaultValue);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// Setters & Getters
|
||||
|
|
@ -174,6 +178,22 @@ public class AppSettings {
|
|||
setStringArray(prefPod, R.string.pref_key__podprofile_followed_tags, tags);
|
||||
}
|
||||
|
||||
public int getUnreadMessageCount(){
|
||||
return getInt(prefPod, R.string.pref_key__podprofile_unread_message_count, 0);
|
||||
}
|
||||
|
||||
public void setUnreadMessageCount(int unreadMessageCount) {
|
||||
setInt(prefPod, R.string.pref_key__podprofile_unread_message_count, unreadMessageCount);
|
||||
}
|
||||
|
||||
public int getNotificationCount(){
|
||||
return getInt(prefPod, R.string.pref_key__podprofile_notification_count, 0);
|
||||
}
|
||||
|
||||
public void setNotificationCount(int notificationCount) {
|
||||
setInt(prefPod, R.string.pref_key__podprofile_notification_count, notificationCount);
|
||||
}
|
||||
|
||||
public boolean isAppendSharedViaApp() {
|
||||
return getBoolean(prefApp, R.string.pref_key__append_shared_via_app, true);
|
||||
}
|
||||
|
|
@ -234,4 +254,8 @@ public class AppSettings {
|
|||
public boolean isIntellihideToolbars() {
|
||||
return getBoolean(prefApp, R.string.pref_key__intellihide_toolbars, true);
|
||||
}
|
||||
|
||||
public boolean isShowExitButtonInNavAlso(){
|
||||
return getBoolean(prefApp, R.string.pref_key__show_exit_button_in_nav_also, false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,8 @@ public class PodUserProfile {
|
|||
name = appSettings.getName();
|
||||
podAspects = appSettings.getPodAspects();
|
||||
followedTags = appSettings.getFollowedTags();
|
||||
notificationCount = appSettings.getNotificationCount();
|
||||
unreadMessagesCount = appSettings.getUnreadMessageCount();
|
||||
}
|
||||
|
||||
public PodUserProfile(App app, Handler callbackHandler, WebUserProfileChangedListener listener) {
|
||||
|
|
@ -102,11 +104,12 @@ public class PodUserProfile {
|
|||
|
||||
// Unread message count
|
||||
if (json.has("notifications_count") && loadNotificationCount(json.getInt("notifications_count"))) {
|
||||
appSettings.setNotificationCount(notificationCount);
|
||||
}
|
||||
|
||||
// Unread message count
|
||||
if (json.has("unread_messages_count") && loadUnreadMessagesCount(json.getInt("unread_messages_count"))) {
|
||||
appSettings.setPodAspects(podAspects);
|
||||
appSettings.setUnreadMessageCount(unreadMessagesCount);
|
||||
}
|
||||
|
||||
// Aspect
|
||||
|
|
|
|||
|
|
@ -16,33 +16,15 @@
|
|||
|
||||
If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.dfa.diaspora_android.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
import com.github.dfa.diaspora_android.data.PodAspect;
|
||||
import com.github.dfa.diaspora_android.data.PodUserProfile;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class Helpers {
|
||||
|
||||
public static boolean isOnline(Context context) {
|
||||
ConnectivityManager cnm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo ni = cnm.getActiveNetworkInfo();
|
||||
return ni != null && ni.isConnectedOrConnecting();
|
||||
}
|
||||
|
||||
public static void animateToActivity(Activity from, Class to, boolean finishFromActivity) {
|
||||
Intent intent = new Intent(from, to);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||
|
|
@ -52,103 +34,4 @@ public class Helpers {
|
|||
from.finish();
|
||||
}
|
||||
}
|
||||
|
||||
public static void applyDiasporaMobileSiteChanges(final WebView wv) {
|
||||
wv.loadUrl("javascript: ( function() {" +
|
||||
" document.documentElement.style.paddingBottom = '260px';" +
|
||||
" document.getElementById('main').style.paddingTop = '5px';" +
|
||||
" if(document.getElementById('main_nav')) {" +
|
||||
" document.getElementById('main_nav').parentNode.removeChild(" +
|
||||
" document.getElementById('main_nav'));" +
|
||||
" } else if (document.getElementById('main-nav')) {" +
|
||||
" document.getElementById('main-nav').parentNode.removeChild(" +
|
||||
" document.getElementById('main-nav'));" +
|
||||
" }" +
|
||||
"})();");
|
||||
}
|
||||
|
||||
public static void getNotificationCount(final WebView wv) {
|
||||
wv.loadUrl("javascript: ( function() {" +
|
||||
"if (document.getElementById('notification')) {" +
|
||||
" var count = document.getElementById('notification').innerHTML;" +
|
||||
" AndroidBridge.setNotificationCount(count.replace(/(\\r\\n|\\n|\\r)/gm, \"\"));" +
|
||||
" } else {" +
|
||||
" AndroidBridge.setNotificationCount('0');" +
|
||||
" }" +
|
||||
" if (document.getElementById('conversation')) {" +
|
||||
" var count = document.getElementById('conversation').innerHTML;" +
|
||||
" AndroidBridge.setConversationCount(count.replace(/(\\r\\n|\\n|\\r)/gm, \"\"));" +
|
||||
" } else {" +
|
||||
" AndroidBridge.setConversationCount('0');" +
|
||||
" }" +
|
||||
"})();");
|
||||
}
|
||||
|
||||
public static void getUserProfile(final WebView wv) {
|
||||
// aspects":[{"id":124934,"name":"Friends","selected":true},{"id":124937,"name":"Liked me","selected":false},{"id":124938,"name":"Follow","selected":false},{"id":128327,"name":"Nur ich","selected":false}]
|
||||
wv.loadUrl("javascript: ( function() {" +
|
||||
" if (typeof gon !== 'undefined' && typeof gon.user !== 'undefined') {" +
|
||||
" var followed_tags = document.getElementById(\"followed_tags\");" +
|
||||
" if(followed_tags != null) {" +
|
||||
" try {" +
|
||||
" var links = followed_tags.nextElementSibling.children[0].children;" +
|
||||
" var tags = [];" +
|
||||
" for(var i = 0; i < links.length - 1; i++) {" + // the last element is "Manage followed tags" link
|
||||
" tags.push(links[i].innerText.substring(1));" +
|
||||
" }" +
|
||||
" gon.user[\"android_app.followed_tags\"] = tags;" +
|
||||
" } catch(e) {}" +
|
||||
" }" +
|
||||
" var userProfile = JSON.stringify(gon.user);" +
|
||||
" AndroidBridge.setUserProfile(userProfile.toString());" +
|
||||
" } " +
|
||||
"})();");
|
||||
}
|
||||
|
||||
public static void showAspectList(final WebView wv, final App app) {
|
||||
wv.stopLoading();
|
||||
PodUserProfile profile = app.getPodUserProfile();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("<html><body style='margin-top: 25px; margin-left:auto;margin-right:auto; font-size: 400%;'>");
|
||||
|
||||
// Content
|
||||
for (PodAspect aspect : profile.getAspects()) {
|
||||
sb.append("<span style='margin-left: 30px; '></span>» ");
|
||||
sb.append(aspect.toHtmlLink(app));
|
||||
sb.append("<hr style='height:5px;' />");
|
||||
}
|
||||
|
||||
// End
|
||||
sb.append("</body></html>");
|
||||
wv.loadDataWithBaseURL(null, sb.toString(), "text/html", "UTF-16", null);
|
||||
}
|
||||
|
||||
public static void showFollowedTagsList(final WebView wv, final App app) {
|
||||
wv.stopLoading();
|
||||
PodUserProfile profile = app.getPodUserProfile();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("<html><body style='margin-top: 25px; margin-left:auto;margin-right:auto; font-size: 400%;'>");
|
||||
|
||||
// Content
|
||||
AppSettings appSettings = app.getSettings();
|
||||
sb.append("<span style='margin-left: 30px; '></span>» ");
|
||||
sb.append(String.format(Locale.getDefault(),
|
||||
"<a href='https://%s/followed_tags' style='color: #000000; text-decoration: none;'><b>%s</b></a>",
|
||||
appSettings.getPodDomain(), app.getString(R.string.all_tags)));
|
||||
sb.append("<hr style='height:5px;' />");
|
||||
for (String tag: profile.getFollowedTags()) {
|
||||
sb.append("<span style='margin-left: 30px; '></span>» ");
|
||||
sb.append(String.format(Locale.getDefault(),
|
||||
"<a href='https://%s/tags/%s' style='color: #000000; text-decoration: none;'>#%s</a>",
|
||||
appSettings.getPodDomain(), tag, tag));
|
||||
sb.append("<hr style='height:5px;' />");
|
||||
}
|
||||
|
||||
// End
|
||||
sb.append("</body></html>");
|
||||
wv.loadDataWithBaseURL(null, sb.toString(), "text/html", "UTF-16", null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
This file is part of the Diaspora for Android.
|
||||
|
||||
Diaspora for Android is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Diaspora for Android is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the Diaspora for Android.
|
||||
|
||||
If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.dfa.diaspora_android.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Html;
|
||||
import android.webkit.URLUtil;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
import com.github.dfa.diaspora_android.data.PodAspect;
|
||||
import com.github.dfa.diaspora_android.data.PodUserProfile;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by Gregor Santner on 07.08.16.
|
||||
* https://gsantner.github.io
|
||||
*/
|
||||
public class WebHelper {
|
||||
|
||||
public static boolean isOnline(Context context) {
|
||||
ConnectivityManager cnm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo ni = cnm.getActiveNetworkInfo();
|
||||
return ni != null && ni.isConnectedOrConnecting();
|
||||
}
|
||||
|
||||
public static String replaceUrlWithMarkdown(String url){
|
||||
if( url != null && URLUtil.isHttpUrl(url) || URLUtil.isHttpsUrl(url)){
|
||||
return "<" + url + ">";
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
public static String escapeHtmlText(String text){
|
||||
text = Html.escapeHtml(text);;
|
||||
text = text.replace("\n", " ");
|
||||
return text;
|
||||
}
|
||||
|
||||
public static void optimizeMobileSiteLayout(final WebView wv) {
|
||||
wv.loadUrl("javascript: ( function() {" +
|
||||
" if (document.documentElement == null || document.documentElement.style == null) { return; }" +
|
||||
" document.documentElement.style.paddingBottom = '260px';" +
|
||||
" document.getElementById('main').style.paddingTop = '5px';" +
|
||||
" if(document.getElementById('main_nav')) {" +
|
||||
" document.getElementById('main_nav').parentNode.removeChild(" +
|
||||
" document.getElementById('main_nav'));" +
|
||||
" } else if (document.getElementById('main-nav')) {" +
|
||||
" document.getElementById('main-nav').parentNode.removeChild(" +
|
||||
" document.getElementById('main-nav'));" +
|
||||
" }" +
|
||||
"})();");
|
||||
}
|
||||
|
||||
public static void getUserProfile(final WebView wv) {
|
||||
// aspects":[{"id":124934,"name":"Friends","selected":true},{"id":124937,"name":"Liked me","selected":false},{"id":124938,"name":"Follow","selected":false},{"id":128327,"name":"Nur ich","selected":false}]
|
||||
wv.loadUrl("javascript: ( function() {" +
|
||||
" if (typeof gon !== 'undefined' && typeof gon.user !== 'undefined') {" +
|
||||
" var followed_tags = document.getElementById(\"followed_tags\");" +
|
||||
" if(followed_tags != null) {" +
|
||||
" try {" +
|
||||
" var links = followed_tags.nextElementSibling.children[0].children;" +
|
||||
" var tags = [];" +
|
||||
" for(var i = 0; i < links.length - 1; i++) {" + // the last element is "Manage followed tags" link
|
||||
" tags.push(links[i].innerText.substring(1));" +
|
||||
" }" +
|
||||
" gon.user[\"android_app.followed_tags\"] = tags;" +
|
||||
" } catch(e) {}" +
|
||||
" }" +
|
||||
" var userProfile = JSON.stringify(gon.user);" +
|
||||
" AndroidBridge.setUserProfile(userProfile.toString());" +
|
||||
" } " +
|
||||
"})();");
|
||||
}
|
||||
|
||||
public static void showAspectList(final WebView wv, final App app) {
|
||||
wv.stopLoading();
|
||||
PodUserProfile profile = app.getPodUserProfile();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("<html><body style='margin-top: 25px; margin-left:auto;margin-right:auto; font-size: 400%;'>");
|
||||
|
||||
// Content
|
||||
for (PodAspect aspect : profile.getAspects()) {
|
||||
sb.append("<span style='margin-left: 30px; '></span>» ");
|
||||
sb.append(aspect.toHtmlLink(app));
|
||||
sb.append("<hr style='height:5px;' />");
|
||||
}
|
||||
|
||||
// End
|
||||
sb.append("</body></html>");
|
||||
wv.loadDataWithBaseURL(null, sb.toString(), "text/html", "UTF-16", null);
|
||||
}
|
||||
|
||||
public static void showFollowedTagsList(final WebView wv, final App app) {
|
||||
wv.stopLoading();
|
||||
PodUserProfile profile = app.getPodUserProfile();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("<html><body style='margin-top: 25px; margin-left:auto;margin-right:auto; font-size: 400%;'>");
|
||||
|
||||
// Content
|
||||
AppSettings appSettings = app.getSettings();
|
||||
sb.append("<span style='margin-left: 30px; '></span>» ");
|
||||
sb.append(String.format(Locale.getDefault(),
|
||||
"<a href='https://%s/followed_tags' style='color: #000000; text-decoration: none;'><b>%s</b></a>",
|
||||
appSettings.getPodDomain(), app.getString(R.string.all_tags)));
|
||||
sb.append("<hr style='height:5px;' />");
|
||||
for (String tag: profile.getFollowedTags()) {
|
||||
sb.append("<span style='margin-left: 30px; '></span>» ");
|
||||
sb.append(String.format(Locale.getDefault(),
|
||||
"<a href='https://%s/tags/%s' style='color: #000000; text-decoration: none;'>#%s</a>",
|
||||
appSettings.getPodDomain(), tag, tag));
|
||||
sb.append("<hr style='height:5px;' />");
|
||||
}
|
||||
|
||||
// End
|
||||
sb.append("</body></html>");
|
||||
wv.loadDataWithBaseURL(null, sb.toString(), "text/html", "UTF-16", null);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue