Extract FABCallback

This commit is contained in:
ligi 2015-02-19 17:21:11 +01:00
parent 7393e0e10e
commit 7b6c4b3a35
2 changed files with 44 additions and 29 deletions

View file

@ -0,0 +1,43 @@
package org.ligi.passandroid.ui;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import com.afollestad.materialdialogs.MaterialDialog;
import org.ligi.axt.AXT;
import org.ligi.passandroid.App;
import org.ligi.passandroid.helper.PassUtil;
import org.ligi.passandroid.model.FiledPass;
class FABCallback implements MaterialDialog.ListCallback {
private final Activity activityContext;
FABCallback(Activity activityContext) {
this.activityContext = activityContext;
}
@Override
public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
switch (i) {
case 0: // scan
final Intent intent = new Intent(activityContext, SearchPassesIntentService.class);
activityContext.startService(intent);
break;
case 1: // demo-pass
AXT.at(activityContext).startCommonIntent().openUrl("http://ligi.de/passandroid_samples/index.html");
break;
case 2: // add
final FiledPass pass = PassUtil.createEmptyPass();
App.getPassStore().setCurrentPass(pass);
pass.save(App.getPassStore());
AXT.at(activityContext).startCommonIntent().activityFromClass(PassEditActivity.class);
break;
}
}
}

View file

@ -14,26 +14,20 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Toast;
import com.afollestad.materialdialogs.MaterialDialog;
import com.androidquery.service.MarketService;
import com.melnykov.fab.FloatingActionButton;
import com.squareup.otto.Subscribe;
import org.ligi.axt.AXT;
import org.ligi.passandroid.App;
import org.ligi.passandroid.R;
import org.ligi.passandroid.Tracker;
import org.ligi.passandroid.TrackerInterface;
import org.ligi.passandroid.events.NavigationOpenedEvent;
import org.ligi.passandroid.events.SortOrderChangeEvent;
import org.ligi.passandroid.events.TypeFocusEvent;
import org.ligi.passandroid.helper.PassUtil;
import org.ligi.passandroid.model.FiledPass;
import org.ligi.passandroid.model.PassStore;
import org.ligi.tracedroid.TraceDroid;
import org.ligi.tracedroid.logging.Log;
import org.ligi.tracedroid.sending.TraceDroidEmailSender;
import butterknife.ButterKnife;
@ -62,29 +56,7 @@ public class PassListActivity extends ActionBarActivity {
new MaterialDialog.Builder(this)
.title(getString(R.string.fab_add_dialog_title))
.items(R.array.items)
.itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
switch (i) {
case 0: // scan
final Intent intent = new Intent(PassListActivity.this, SearchPassesIntentService.class);
startService(intent);
break;
case 1: // demo-pass
AXT.at(PassListActivity.this).startCommonIntent().openUrl("http://ligi.de/passandroid_samples/index.html");
break;
case 2: // add
final FiledPass pass = PassUtil.createEmptyPass();
App.getPassStore().setCurrentPass(pass);
pass.save(App.getPassStore());
AXT.at(PassListActivity.this).startCommonIntent().activityFromClass(PassEditActivity.class);
break;
}
}
})
.itemsCallback( new FABCallback(this))
.negativeText(android.R.string.cancel)
.show();
}