mirror of
https://github.com/gsantner/dandelion
synced 2025-12-15 00:31:11 +01:00
Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment
This commit is contained in:
parent
e06e2f3ba1
commit
94895f78e0
7 changed files with 202 additions and 281 deletions
|
|
@ -66,6 +66,7 @@ import com.github.dfa.diaspora_android.fragment.BrowserFragment;
|
|||
import com.github.dfa.diaspora_android.fragment.CustomFragment;
|
||||
import com.github.dfa.diaspora_android.fragment.DiasporaStreamFragment;
|
||||
import com.github.dfa.diaspora_android.fragment.HashtagListFragment;
|
||||
import com.github.dfa.diaspora_android.fragment.PodSelectionFragment;
|
||||
import com.github.dfa.diaspora_android.fragment.TestFragment;
|
||||
import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
|
||||
import com.github.dfa.diaspora_android.receiver.OpenExternalLinkReceiver;
|
||||
|
|
@ -179,12 +180,17 @@ public class MainActivity extends AppCompatActivity
|
|||
MainActivity.this.setTitle(title);
|
||||
}
|
||||
});
|
||||
//Handle intent
|
||||
Intent intent = getIntent();
|
||||
if(intent != null && intent.getAction() != null) {
|
||||
handleIntent(intent);
|
||||
|
||||
if(!appSettings.hasPodDomain()) {
|
||||
showFragment(getFragment(PodSelectionFragment.TAG));
|
||||
} else {
|
||||
openDiasporaUrl(urls.getStreamUrl());
|
||||
//Handle intent
|
||||
Intent intent = getIntent();
|
||||
if (intent != null && intent.getAction() != null) {
|
||||
handleIntent(intent);
|
||||
} else {
|
||||
openDiasporaUrl(urls.getStreamUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -261,6 +267,10 @@ public class MainActivity extends AppCompatActivity
|
|||
HashtagListFragment hlf = new HashtagListFragment();
|
||||
fm.beginTransaction().add(hlf, fragmentTag).commit();
|
||||
return hlf;
|
||||
case PodSelectionFragment.TAG:
|
||||
PodSelectionFragment psf = new PodSelectionFragment();
|
||||
fm.beginTransaction().add(psf, fragmentTag).commit();
|
||||
return psf;
|
||||
case TestFragment.TAG:
|
||||
default:
|
||||
AppLog.e(this,"Invalid Fragment Tag: "+fragmentTag
|
||||
|
|
@ -388,9 +398,9 @@ public class MainActivity extends AppCompatActivity
|
|||
AppLog.v(this, "Intent has a delicious URL for us: "+loadUrl);
|
||||
}
|
||||
} else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
|
||||
AppLog.v(this, "Reset pod data and animate to PodSelectionActivity");
|
||||
AppLog.v(this, "Reset pod data and show PodSelectionFragment");
|
||||
app.resetPodData(((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView());
|
||||
Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true);
|
||||
showFragment(getFragment(PodSelectionFragment.TAG));
|
||||
} else if (ACTION_CLEAR_CACHE.equals(action)) {
|
||||
AppLog.v(this, "Clear WebView cache");
|
||||
((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView().clearCache(true);
|
||||
|
|
@ -510,13 +520,24 @@ public class MainActivity extends AppCompatActivity
|
|||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
AppLog.v(this, "onCreateOptionsMenu()");
|
||||
//Clear the menus
|
||||
menu.clear();
|
||||
getMenuInflater().inflate(R.menu.main__menu_top, menu);
|
||||
toolbarBottom.getMenu().clear();
|
||||
getMenuInflater().inflate(R.menu.main__menu_bottom, toolbarBottom.getMenu());
|
||||
toolbarBottom.setVisibility(View.VISIBLE);
|
||||
|
||||
CustomFragment top = getTopFragment();
|
||||
if(top != null) {
|
||||
top.onCreateBottomOptionsMenu(toolbarBottom.getMenu(), getMenuInflater());
|
||||
//Are we displaying a Fragment other than PodSelectionFragment?
|
||||
if(!top.getFragmentTag().equals(PodSelectionFragment.TAG)) {
|
||||
getMenuInflater().inflate(R.menu.main__menu_top, menu);
|
||||
getMenuInflater().inflate(R.menu.main__menu_bottom, toolbarBottom.getMenu());
|
||||
top.onCreateBottomOptionsMenu(toolbarBottom.getMenu(), getMenuInflater());
|
||||
}
|
||||
//PodSelectionFragment
|
||||
else {
|
||||
//Hide bottom toolbar
|
||||
toolbarBottom.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
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.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.util.Helpers;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
||||
public class SplashActivity extends AppCompatActivity {
|
||||
private App app;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.splash__activity);
|
||||
ButterKnife.bind(this);
|
||||
app = (App) getApplication();
|
||||
|
||||
int delay = getResources().getInteger(R.integer.splash_delay);
|
||||
new Handler().postDelayed(startActivityRunnable, delay);
|
||||
}
|
||||
|
||||
private final Runnable startActivityRunnable = new Runnable() {
|
||||
public void run() {
|
||||
boolean hasPodDomain = app.getSettings().hasPodDomain();
|
||||
Helpers.animateToActivity(SplashActivity.this,
|
||||
hasPodDomain ? MainActivity.class : PodSelectionActivity.class,
|
||||
true
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -1,22 +1,4 @@
|
|||
/*
|
||||
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.activity;
|
||||
package com.github.dfa.diaspora_android.fragment;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
|
|
@ -28,64 +10,103 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Editable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.CookieManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.github.dfa.diaspora_android.App;
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.activity.MainActivity;
|
||||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
import com.github.dfa.diaspora_android.task.GetPodsService;
|
||||
import com.github.dfa.diaspora_android.util.Helpers;
|
||||
import com.github.dfa.diaspora_android.util.AppLog;
|
||||
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
||||
import com.github.dfa.diaspora_android.util.WebHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnItemClick;
|
||||
/**
|
||||
* Fragment that lets the user choose a Pod
|
||||
* Created by vanitas on 01.10.16.
|
||||
*/
|
||||
|
||||
public class PodSelectionFragment extends CustomFragment {
|
||||
public static final String TAG = "com.github.dfa.diaspora_android.PodSelectionFragment";
|
||||
|
||||
public class PodSelectionActivity extends AppCompatActivity {
|
||||
private App app;
|
||||
protected EditText editFilter;
|
||||
protected ListView listPods;
|
||||
protected ImageView selectPodButton;
|
||||
|
||||
@BindView(R.id.podselection__edit_filter)
|
||||
EditText editFilter;
|
||||
|
||||
@BindView(R.id.podselection__listpods)
|
||||
ListView listPods;
|
||||
|
||||
@BindView(R.id.main__topbar)
|
||||
Toolbar toolbar;
|
||||
protected App app;
|
||||
protected AppSettings appSettings;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.podselection__activity);
|
||||
ButterKnife.bind(this);
|
||||
app = (App) getApplication();
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
|
||||
listPods.setTextFilterEnabled(true);
|
||||
setListedPods(app.getSettings().getPreviousPodlist());
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(podListReceiver, new IntentFilter(GetPodsService.MESSAGE_PODS_RECEIVED));
|
||||
|
||||
if (!WebHelper.isOnline(PodSelectionActivity.this)) {
|
||||
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
AppLog.d(this, "onCreateView()");
|
||||
return inflater.inflate(R.layout.podselection__fragment, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
this.app = (App) getActivity().getApplication();
|
||||
this.appSettings = app.getSettings();
|
||||
|
||||
this.editFilter = (EditText) view.findViewById(R.id.podselection__edit_filter);
|
||||
this.listPods = (ListView) view.findViewById(R.id.podselection__listpods);
|
||||
this.selectPodButton = (ImageView) view.findViewById(R.id.podselection__button_select_pod);
|
||||
|
||||
listPods.setTextFilterEnabled(true);
|
||||
listPods.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
showPodConfirmationDialog((String) listPods.getAdapter().getItem(i));
|
||||
}
|
||||
});
|
||||
setListedPods(appSettings.getPreviousPodlist());
|
||||
LocalBroadcastManager.getInstance(getContext()).registerReceiver(podListReceiver, new IntentFilter(GetPodsService.MESSAGE_PODS_RECEIVED));
|
||||
if (!WebHelper.isOnline(getContext())) {
|
||||
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
selectPodButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (editFilter.getText().length() > 4 && editFilter.getText().toString().contains("")) {
|
||||
showPodConfirmationDialog(editFilter.getText().toString());
|
||||
} else {
|
||||
Snackbar.make(listPods, R.string.valid_pod, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFragmentTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
/* Nothing to do */
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private final BroadcastReceiver podListReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
|
|
@ -104,20 +125,11 @@ public class PodSelectionActivity extends AppCompatActivity {
|
|||
}
|
||||
};
|
||||
|
||||
@OnClick(R.id.podselection__button_select_pod)
|
||||
public void onButtonSelectPodClicked(View view) {
|
||||
if (editFilter.getText().length() > 4 && editFilter.getText().toString().contains("")) {
|
||||
showPodConfirmationDialog(editFilter.getText().toString());
|
||||
} else {
|
||||
Snackbar.make(listPods, R.string.valid_pod, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Intent i = new Intent(PodSelectionActivity.this, GetPodsService.class);
|
||||
startService(i);
|
||||
Intent i = new Intent(getContext(), GetPodsService.class);
|
||||
getContext().startService(i);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -128,7 +140,7 @@ public class PodSelectionActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
final ArrayAdapter<String> adapter = new ArrayAdapter<>(
|
||||
PodSelectionActivity.this,
|
||||
getContext(),
|
||||
android.R.layout.simple_list_item_1,
|
||||
listedPodsList);
|
||||
|
||||
|
|
@ -154,24 +166,19 @@ public class PodSelectionActivity extends AppCompatActivity {
|
|||
});
|
||||
}
|
||||
|
||||
@OnItemClick(R.id.podselection__listpods)
|
||||
public void onListPodsItemClicked(int position) {
|
||||
showPodConfirmationDialog((String) listPods.getAdapter().getItem(position));
|
||||
}
|
||||
|
||||
private void showPodConfirmationDialog(final String selectedPod) {
|
||||
// Make a clickable link
|
||||
final SpannableString dialogMessage = new SpannableString(getString(R.string.confirm_pod, selectedPod));
|
||||
Linkify.addLinks(dialogMessage, Linkify.ALL);
|
||||
|
||||
// Check if online
|
||||
if (!WebHelper.isOnline(PodSelectionActivity.this)) {
|
||||
if (!WebHelper.isOnline(getContext())) {
|
||||
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// Show dialog
|
||||
new AlertDialog.Builder(PodSelectionActivity.this)
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(getString(R.string.confirmation))
|
||||
.setMessage(dialogMessage)
|
||||
.setPositiveButton(android.R.string.yes,
|
||||
|
|
@ -201,40 +208,28 @@ public class PodSelectionActivity extends AppCompatActivity {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Helpers.animateToActivity(this, MainActivity.class, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
Snackbar.make(listPods, R.string.confirm_exit, Snackbar.LENGTH_LONG)
|
||||
.setAction(android.R.string.yes, new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
((MainActivity)getActivity()).openDiasporaUrl(new DiasporaUrlHelper(appSettings).getPodUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(podListReceiver);
|
||||
public void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(podListReceiver);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.podselection__menu, menu);
|
||||
return true;
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.podselection__menu, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_reload: {
|
||||
if (WebHelper.isOnline(PodSelectionActivity.this)) {
|
||||
Intent i = new Intent(PodSelectionActivity.this, GetPodsService.class);
|
||||
startService(i);
|
||||
if (WebHelper.isOnline(getContext())) {
|
||||
Intent i = new Intent(getContext(), GetPodsService.class);
|
||||
getContext().startService(i);
|
||||
return true;
|
||||
} else {
|
||||
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
||||
Loading…
Add table
Add a link
Reference in a new issue