1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 04:12:08 +01:00

Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment

This commit is contained in:
vanitasvitae 2016-10-01 01:18:42 +02:00
parent e06e2f3ba1
commit 94895f78e0
7 changed files with 202 additions and 281 deletions

View file

@ -12,43 +12,26 @@
android:name="com.github.dfa.diaspora_android.App"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<provider
android:name="com.github.dfa.diaspora_android.data.HashtagProvider"
android:authorities="com.github.dfa.diaspora_android.mainactivity" />
<activity
android:name="com.github.dfa.diaspora_android.activity.SplashActivity"
android:launchMode="singleInstance"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.PodSelectionActivity"
android:launchMode="singleInstance"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/title_activity_pods"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="stateHidden" >
</activity>
<service
android:name="com.github.dfa.diaspora_android.task.GetPodsService"
android:enabled="true"
android:exported="false" />
<activity
android:name=".activity.SettingsActivity"
android:launchMode="singleInstance"
android:theme="@style/AppTheme"
android:label="@string/settings">
</activity>
android:label="@string/settings" />
<service
android:name="com.github.dfa.diaspora_android.task.GetPodsService"
android:enabled="true"
android:exported="false" >
</service>
<activity
android:name=".activity.AboutActivity"
android:label="@string/about_activity__title_about_app"
android:theme="@style/AppTheme.NoActionBar"/>
<activity
android:name=".activity.MainActivity"
@ -58,6 +41,11 @@
android:theme="@style/AppTheme.NoActionBar"
android:label="@string/diaspora">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
@ -255,9 +243,7 @@
</intent-filter>
</activity>
<activity
android:name=".activity.AboutActivity"
android:label="@string/about_activity__title_about_app"
android:theme="@style/AppTheme.NoActionBar"/>
</application>
</manifest>

View file

@ -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;
}

View file

@ -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
);
}
};
}

View file

@ -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();

View file

@ -1,88 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.PodSelectionActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/main__topbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/podselection__activity">
<ListView
android:id="@+id/podselection__listpods"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/podselection__podupti_notice"
android:layout_below="@+id/podselection__edit_filter"
android:choiceMode="singleChoice" />
<EditText
android:id="@+id/podselection__edit_filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/textView"
android:layout_toStartOf="@+id/podselection__button_select_pod"
android:hint="@string/filter_hint"
android:inputType="textUri|textWebEditText" />
<ImageView
android:id="@+id/podselection__button_select_pod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/podselection__listpods"
android:layout_alignEnd="@+id/podselection__listpods"
android:layout_alignTop="@+id/podselection__edit_filter"
android:contentDescription="@string/confirm_url"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="@drawable/ic_arrow_forward_black_48px" />
<TextView
android:id="@+id/podselection__podupti_notice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:autoLink="web"
android:text="@string/podlist_source_note"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/podselection__listpods"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="0dp"
android:gravity="center_vertical"
android:text="@string/prefix_https"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

View file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/podselection__fragment">
<ListView
android:id="@+id/podselection__listpods"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/podselection__podupti_notice"
android:layout_below="@+id/podselection__edit_filter"
android:choiceMode="singleChoice" />
<EditText
android:id="@+id/podselection__edit_filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/textView"
android:layout_toStartOf="@+id/podselection__button_select_pod"
android:hint="@string/filter_hint"
android:inputType="textUri|textWebEditText" />
<ImageView
android:id="@+id/podselection__button_select_pod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/podselection__listpods"
android:layout_alignEnd="@+id/podselection__listpods"
android:layout_alignTop="@+id/podselection__edit_filter"
android:contentDescription="@string/confirm_url"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="@drawable/ic_arrow_forward_black_48px" />
<TextView
android:id="@+id/podselection__podupti_notice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:autoLink="web"
android:text="@string/podlist_source_note"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/podselection__listpods"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="0dp"
android:gravity="center_vertical"
android:text="@string/prefix_https"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>

View file

@ -1,7 +1,5 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".activity.PodSelectionActivity">
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_reload"