public SectionsPagerAdapter(FragmentManager fm, Context ctx) {
super(fm);
fragments = new Fragment[3];
fragments[0] = PlaceholderFragment.newInstance(1);
fragments[1] = PlaceholderFragment.newInstance(2);
fragments[2] = PlaceholderFragment.newInstance(3);
titles = new String[3];
titles[0] = ctx.getString(R.string.googleTitle);
titles[1] = ctx.getString(R.string.yandexTitle);
titles[2] = ctx.getString(R.string.oneDriveTitle);
}
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_activity_all);
Log.w(TAG, "onCreate");
if (allModels == null) {
converter = new Converter();
mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
fileWork = new FileWork();
server = RetrofitBuilder.getOAuthClient(this);
presenterGoogle = new GoogleCloudPresenter(server, context, this);
presenterGoogle.setPathGoogle(presenterGoogle.googleMoveFolder("root"));
presenterGoogle.setTitleGoogle("MCloud");
// progressBar = (ProgressBar) findViewById(R.id.progress);
ActivityCompat.requestPermissions(LoginActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), getApplicationContext());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
} else adapter = new Data_Adapter(context, R.layout.list_item, allModels);
}
@Override
public void onBackPressed() {
Log.e("TAG","pos: "+mViewPager.getCurrentItem());
if (mViewPager.getCurrentItem()==0) {
if (googleFlag) {
String path = "root";
String title = "MCloud";
if (presenterGoogle.getPathGoogle().size() - 2 >= 0) {
Log.w(TAG, "path = " + path);
Log.w(TAG, "title = " + title + " title -1 = " + presenterGoogle.getTitleGoogle().get(presenterGoogle.getTitleGoogle().size() - 2));
path = presenterGoogle.getPathGoogle().get(presenterGoogle.getPathGoogle().size() - 2);
title = presenterGoogle.getTitleGoogle().get(presenterGoogle.getTitleGoogle().size() - 2);
}
Log.w("back", path);
if (presenterGoogle.getPathGoogle().size() - 1 > 0) {
Log.w(TAG, "удаляем из getPath последний элемент = " + path);
presenterGoogle.getPathGoogle().remove(presenterGoogle.getPathGoogle().size() - 1);
presenterGoogle.getTitleGoogle().remove(presenterGoogle.getTitleGoogle().size() - 1);
setTitle(title);
if (path == "root")
path = presenterGoogle.googleMoveFolder(path);
presenterGoogle.listGDriveUserFiles(path);
}
else {
super.onBackPressed();
}
}
}
else
super.onBackPressed();
}