mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-28 11:52:18 -05:00
Refactor settings from activity to fragment implementation.
This commit is contained in:
parent
bb8cd1a4de
commit
c5dd873e9d
@ -20,6 +20,8 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
package org.yaaic.activity;
|
package org.yaaic.activity;
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentTransaction;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
@ -29,8 +31,6 @@ import android.support.v4.widget.DrawerLayout;
|
|||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.support.v7.app.ActionBarDrawerToggle;
|
import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@ -39,14 +39,13 @@ import android.widget.TextView;
|
|||||||
import org.yaaic.R;
|
import org.yaaic.R;
|
||||||
import org.yaaic.Yaaic;
|
import org.yaaic.Yaaic;
|
||||||
import org.yaaic.fragment.OverviewFragment;
|
import org.yaaic.fragment.OverviewFragment;
|
||||||
|
import org.yaaic.fragment.SettingsFragment;
|
||||||
import org.yaaic.irc.IRCBinder;
|
import org.yaaic.irc.IRCBinder;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Extra;
|
import org.yaaic.model.Extra;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
import org.yaaic.model.Status;
|
import org.yaaic.model.Status;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main activity of Yaaic. We'll add, remove and replace fragments here.
|
* The main activity of Yaaic. We'll add, remove and replace fragments here.
|
||||||
*/
|
*/
|
||||||
@ -64,6 +63,10 @@ public class MainActivity extends ActionBarActivity implements OverviewFragment.
|
|||||||
|
|
||||||
initializeToolbar();
|
initializeToolbar();
|
||||||
initializeDrawer();
|
initializeDrawer();
|
||||||
|
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
onOverview(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeToolbar() {
|
public void initializeToolbar() {
|
||||||
@ -80,7 +83,7 @@ public class MainActivity extends ActionBarActivity implements OverviewFragment.
|
|||||||
LinearLayout drawerContent = (LinearLayout) findViewById(R.id.drawer_content);
|
LinearLayout drawerContent = (LinearLayout) findViewById(R.id.drawer_content);
|
||||||
|
|
||||||
for (final Server server : Yaaic.getInstance().getServersAsArrayList()) {
|
for (final Server server : Yaaic.getInstance().getServersAsArrayList()) {
|
||||||
TextView serverView = (TextView) getLayoutInflater().inflate(R.layout.item_navigation, drawer, false);
|
TextView serverView = (TextView) getLayoutInflater().inflate(R.layout.item_drawer_server, drawer, false);
|
||||||
serverView.setText(server.getTitle());
|
serverView.setText(server.getTitle());
|
||||||
|
|
||||||
serverView.setOnClickListener(new View.OnClickListener() {
|
serverView.setOnClickListener(new View.OnClickListener() {
|
||||||
@ -148,10 +151,20 @@ public class MainActivity extends ActionBarActivity implements OverviewFragment.
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onOverview(View view) {
|
||||||
|
switchToFragment(new OverviewFragment(), OverviewFragment.TRANSACTION_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
public void onSettings(View view) {
|
public void onSettings(View view) {
|
||||||
|
switchToFragment(new SettingsFragment(), SettingsFragment.TRANSACTION_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void switchToFragment(Fragment fragment, String tag) {
|
||||||
drawer.closeDrawers();
|
drawer.closeDrawers();
|
||||||
|
|
||||||
startActivity(new Intent(this, SettingsActivity.class));
|
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||||
|
transaction.replace(R.id.container, fragment, tag);
|
||||||
|
transaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAbout(View view) {
|
public void onAbout(View view) {
|
||||||
|
@ -55,6 +55,8 @@ import org.yaaic.receiver.ServerReceiver;
|
|||||||
* Fragment showing a list of configured servers.
|
* Fragment showing a list of configured servers.
|
||||||
*/
|
*/
|
||||||
public class OverviewFragment extends Fragment implements ServerListener, ServersAdapter.ClickListener, View.OnClickListener {
|
public class OverviewFragment extends Fragment implements ServerListener, ServersAdapter.ClickListener, View.OnClickListener {
|
||||||
|
public static final String TRANSACTION_TAG = "fragment_overview";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback interface to be implemented by Activities using this fragment.
|
* Callback interface to be implemented by Activities using this fragment.
|
||||||
*/
|
*/
|
||||||
|
20
app/src/main/java/org/yaaic/fragment/SettingsFragment.java
Normal file
20
app/src/main/java/org/yaaic/fragment/SettingsFragment.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package org.yaaic.fragment;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceFragment;
|
||||||
|
|
||||||
|
import org.yaaic.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fragment displaying all settings.
|
||||||
|
*/
|
||||||
|
public class SettingsFragment extends PreferenceFragment {
|
||||||
|
public static final String TRANSACTION_TAG = "fragment_settings";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
}
|
||||||
|
}
|
@ -36,13 +36,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/container"
|
android:id="@+id/container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<fragment
|
|
||||||
android:name="org.yaaic.fragment.OverviewFragment"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user