Skip to content
Snippets Groups Projects
Select Git revision
  • e78e62d9cdf2d7ab0735c7ed66d3813ba9bca8c5
  • master default protected
  • release/202005
  • release/202001
  • release/201912
  • release/windows-test/201910
  • release/201908
  • release/201906
  • release/201905
  • release/201904
  • release/201903
  • release/201902
  • release/201901
  • release/201812
  • release/201811
  • release/201808
  • wip/patches_poly_2017/cedryk_doucet/abderahmane_bouziane
  • releases/beta1
  • android/release_463
  • android/release_462
  • android/release_461
  • android/release_460
  • android/release_459
  • android/release_458
  • android/release_457
  • android/release_456
  • android/release_455
  • android/release_454
  • android/release_453
  • android/release_452
  • android/release_451
  • android/release_450
  • android/release_449
  • android/release_448
  • android/release_447
  • android/release_446
  • android/release_445
  • android/release_444
38 results

HomeAccountCreationFragment.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    HomeAccountCreationFragment.java 5.11 KiB
    /*
     *  Copyright (C) 2004-2019 Savoir-faire Linux Inc.
     *
     *  Author: Aline Bonnet <aline.bonnet@savoirfairelinux.com>
     *
     *  This program is free software; you can redistribute it and/or modify
     *  it under the terms of the GNU 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 General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program; if not, write to the Free Software
     *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     */
    package cx.ring.account;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    import androidx.annotation.NonNull;
    import androidx.fragment.app.Fragment;
    
    import com.google.android.material.snackbar.Snackbar;
    
    import butterknife.BindView;
    import butterknife.OnClick;
    import cx.ring.R;
    import cx.ring.dependencyinjection.JamiInjectionComponent;
    import cx.ring.mvp.BaseSupportFragment;
    import cx.ring.utils.AndroidFileUtils;
    import io.reactivex.android.schedulers.AndroidSchedulers;
    
    public class HomeAccountCreationFragment extends BaseSupportFragment<HomeAccountCreationPresenter> implements HomeAccountCreationView {
        private static final int ARCHIVE_REQUEST_CODE = 42;
    
        public static final String TAG = HomeAccountCreationFragment.class.getSimpleName();
    
        @BindView(R.id.ring_add_account)
        protected Button mLinkButton;
    
        @BindView(R.id.ring_create_btn)
        protected Button mCreateButton;
    
        @Override
        public int getLayout() {
            return R.layout.frag_acc_home_create;
        }
    
        @Override
        public void injectFragment(JamiInjectionComponent component) {
            component.inject(this);
        }
    
        @Override
        public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);
            setRetainInstance(true);
        }
    
        @OnClick(R.id.ring_add_account)
        public void linkAccountClicked() {
            presenter.clickOnLinkAccount();
        }
    
        @OnClick(R.id.ring_create_btn)
        public void createAccountClicked() {
            presenter.clickOnCreateAccount();
        }
    
        @OnClick(R.id.account_connect_server)
        public void connectAccountClicked() {
            presenter.clickOnConnectAccount();
        }
    
        @Override
        public void goToAccountCreation() {
            AccountCreationModelImpl ringAccountViewModel = new AccountCreationModelImpl();
            Fragment fragment = JamiAccountCreationFragment.newInstance(ringAccountViewModel);
            replaceFragmentWithSlide(fragment, R.id.wizard_container);
        }
    
        @Override
        public void goToAccountLink() {
            AccountCreationModelImpl ringAccountViewModel = new AccountCreationModelImpl();
            ringAccountViewModel.setLink(true);
            Fragment fragment = RingLinkAccountFragment.newInstance(ringAccountViewModel);
            replaceFragmentWithSlide(fragment, R.id.wizard_container);
        }
    
        @Override
        public void goToAccountConnect() {
            AccountCreationModelImpl ringAccountViewModel = new AccountCreationModelImpl();
            ringAccountViewModel.setLink(true);
            Fragment fragment = JamiAccountConnectFragment.newInstance(ringAccountViewModel);
            replaceFragmentWithSlide(fragment, R.id.wizard_container);
        }
    
        @OnClick(R.id.ring_import_account)
        public void performFileSearch() {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("*/*");
            startActivityForResult(intent, ARCHIVE_REQUEST_CODE);
        }
    
        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
            if (requestCode == ARCHIVE_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
                if (resultData != null) {
                    Uri uri = resultData.getData();
                    if (uri != null) {
                        AndroidFileUtils.getCacheFile(requireContext(), uri)
                                .observeOn(AndroidSchedulers.mainThread())
                                .subscribe(file -> {
                                    AccountCreationModelImpl ringAccountViewModel = new AccountCreationModelImpl();
                                    ringAccountViewModel.setLink(true);
                                    ringAccountViewModel.setArchive(file);
                                    Fragment fragment = RingLinkAccountFragment.newInstance(ringAccountViewModel);
                                    replaceFragmentWithSlide(fragment, R.id.wizard_container);
                                }, e-> {
                                    View v = getView();
                                    if (v != null)
                                        Snackbar.make(v, "Can't import archive: " + e.getMessage(), Snackbar.LENGTH_LONG).show();
                                });
                    }
                }
            }
        }
    }