mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 11:21:29 +00:00
Merged ToolbarActivity into SyncthingActivity
This commit is contained in:
parent
953f5e1e82
commit
32be8ba207
2 changed files with 25 additions and 42 deletions
|
@ -4,20 +4,23 @@ import android.content.ComponentName;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
import com.nutomic.syncthingandroid.service.RestApi;
|
||||
import com.nutomic.syncthingandroid.service.SyncthingService;
|
||||
import com.nutomic.syncthingandroid.service.SyncthingServiceBinder;
|
||||
import com.nutomic.syncthingandroid.util.Util;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Connects to {@link SyncthingService} and provides access to it.
|
||||
*/
|
||||
public abstract class SyncthingActivity extends ToolbarBindingActivity implements ServiceConnection {
|
||||
public abstract class SyncthingActivity extends AppCompatActivity implements ServiceConnection {
|
||||
|
||||
public static final String EXTRA_FIRST_START = "com.nutomic.syncthing-android.SyncthingActivity.FIRST_START";
|
||||
|
||||
|
@ -32,6 +35,26 @@ public abstract class SyncthingActivity extends ToolbarBindingActivity implement
|
|||
void onServiceConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Look for a Toolbar in the layout and bind it as the activity's actionbar with reasonable
|
||||
* defaults.
|
||||
*
|
||||
* The Toolbar must exist in the content view and have an id of R.id.toolbar. Trying to call
|
||||
* getSupportActionBar before this Activity's onPostCreate will cause a crash.
|
||||
*/
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
if (toolbar == null)
|
||||
return;
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
//noinspection ConstantConditions
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
unbindService(this);
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package com.nutomic.syncthingandroid.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
|
||||
/**
|
||||
* An activity that onPostCreate will look for a Toolbar in the layout
|
||||
* and bind it as the activity's actionbar with reasonable defaults. <br/>
|
||||
* The Toolbar must exist in the content view and have an id of R.id.toolbar.<br/>
|
||||
* Trying to call getSupportActionBar before this Activity's onPostCreate will cause a crash.
|
||||
*/
|
||||
public abstract class ToolbarBindingActivity extends AppCompatActivity {
|
||||
|
||||
private static final String TAG = "ToolbarBindingActivity";
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
if (toolbar == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
setSupportActionBar(toolbar);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// Workaround for crash on Samsung 4.2 devices.
|
||||
// This should be fixed in support library 24.0.0
|
||||
// https://code.google.com/p/android/issues/detail?id=78377#c364
|
||||
// https://github.com/syncthing/syncthing-android/issues/591
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
//noinspection ConstantConditions
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue