/*
* The CroudTrip! application aims at revolutionizing the car-ride-sharing market with its easy,
* user-friendly and highly automated way of organizing shared Trips. Copyright (C) 2015 Nazeeh Ammari,
* Philipp Eichhorn, Ricarda Hohn, Vanessa Lange, Alexander Popp, Frederik Simon, Michael Weber
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU
* Affero General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* This program 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License along with this program.
* If not, see http://www.gnu.org/licenses/.
*/
package org.croudtrip.fragments;
import android.app.Fragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import org.croudtrip.Constants;
import org.croudtrip.R;
import org.croudtrip.account.AccountManager;
import org.croudtrip.gcm.GcmManager;
import org.croudtrip.utils.DefaultTransformer;
import javax.inject.Inject;
import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
import roboguice.fragment.RoboFragment;
import roboguice.inject.InjectView;
import rx.Subscription;
import rx.functions.Action1;
import timber.log.Timber;
/**
* Created by alex on 22.04.15.
*/
public class SettingsFragment extends RoboFragment {
//********************** Variables ***************************//
@Inject
GcmManager gcmManager;
private Button btnversionInfo;
//************************ Methods ***************************//
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toolbar toolbar = ((MaterialNavigationDrawer) this.getActivity()).getToolbar();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
setHasOptionsMenu(true);
View view = inflater.inflate(R.layout.fragment_settings, container, false);
btnversionInfo = (Button) view.findViewById(R.id.settings_version_info);
if(AccountManager.isUserLoggedIn(getActivity().getApplicationContext())) {
Button logoutButton = (Button) view.findViewById(R.id.settings_logout);
logoutButton.setVisibility(View.VISIBLE);
logoutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AccountManager.logout(getActivity().getApplicationContext(), true);
if (gcmManager.isRegistered()) {
Subscription subscription = gcmManager.unregister()
.compose(new DefaultTransformer<Void>())
.retry(3)
.subscribe(new Action1<Void>() {
@Override
public void call(Void aVoid) {
Timber.d("Successfully unregistered");
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
Timber.e(throwable.getMessage());
}
});
}
}
});
}
btnversionInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
LayoutInflater adbInflater = LayoutInflater.from(getActivity());
View dialogLayout = adbInflater.inflate(R.layout.dialog_version_info, null);
adb.setView(dialogLayout);
String title = getResources().getString(R.string.version_info);
try {
PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
title = getResources().getString(R.string.version_info) + ": " + pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
adb.setTitle(title);
adb.setPositiveButton(getResources().getString(R.string.enable_gps_ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
adb.show();
}
});
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
menu.clear();
//inflater.inflate(R.menu.menu_main, menu);
}
}