1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-24 18:02:20 -05:00

Refactor settings from activity to fragment implementation.

This commit is contained in:
Sebastian Kaspari 2015-03-29 16:16:32 +02:00
parent bb8cd1a4de
commit c5dd873e9d
4 changed files with 42 additions and 13 deletions

View File

@ -20,6 +20,8 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.ComponentName;
import android.content.Intent;
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.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
@ -39,14 +39,13 @@ import android.widget.TextView;
import org.yaaic.R;
import org.yaaic.Yaaic;
import org.yaaic.fragment.OverviewFragment;
import org.yaaic.fragment.SettingsFragment;
import org.yaaic.irc.IRCBinder;
import org.yaaic.irc.IRCService;
import org.yaaic.model.Extra;
import org.yaaic.model.Server;
import org.yaaic.model.Status;
import java.util.List;
/**
* 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();
initializeDrawer();
if (savedInstanceState == null) {
onOverview(null);
}
}
public void initializeToolbar() {
@ -80,7 +83,7 @@ public class MainActivity extends ActionBarActivity implements OverviewFragment.
LinearLayout drawerContent = (LinearLayout) findViewById(R.id.drawer_content);
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.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) {
switchToFragment(new SettingsFragment(), SettingsFragment.TRANSACTION_TAG);
}
private void switchToFragment(Fragment fragment, String tag) {
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) {

View File

@ -55,6 +55,8 @@ import org.yaaic.receiver.ServerReceiver;
* Fragment showing a list of configured servers.
*/
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.
*/

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

View File

@ -36,13 +36,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
<FrameLayout
android:id="@+id/container"
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" />
</FrameLayout>
</LinearLayout>