Search in sources :

Example 1 with FilesListModel

use of com.fastaccess.data.dao.FilesListModel in project FastHub by k0shk0sh.

the class AbstractGist method getDisplayTitle.

@NonNull
public SpannableBuilder getDisplayTitle(boolean isFromProfile, boolean gistView) {
    SpannableBuilder spannableBuilder = SpannableBuilder.builder();
    boolean addDescription = true;
    if (!isFromProfile) {
        if (owner != null) {
            spannableBuilder.bold(owner.getLogin());
        } else if (user != null) {
            spannableBuilder.bold(user.getLogin());
        } else {
            spannableBuilder.bold("Anonymous");
        }
        if (!gistView) {
            List<FilesListModel> files = getFilesAsList();
            if (!files.isEmpty()) {
                FilesListModel filesListModel = files.get(0);
                if (!InputHelper.isEmpty(filesListModel.getFilename()) && filesListModel.getFilename().trim().length() > 2) {
                    spannableBuilder.append(" ").append("/").append(" ").append(filesListModel.getFilename());
                    addDescription = false;
                }
            }
        }
    }
    if (!InputHelper.isEmpty(description) && addDescription) {
        if (!InputHelper.isEmpty(spannableBuilder.toString())) {
            spannableBuilder.append(" ").append("/").append(" ");
        }
        spannableBuilder.append(description);
    }
    if (InputHelper.isEmpty(spannableBuilder.toString())) {
        if (isFromProfile) {
            List<FilesListModel> files = getFilesAsList();
            if (!files.isEmpty()) {
                FilesListModel filesListModel = files.get(0);
                if (!InputHelper.isEmpty(filesListModel.getFilename()) && filesListModel.getFilename().trim().length() > 2) {
                    spannableBuilder.append(" ").append(filesListModel.getFilename());
                }
            }
        }
    }
    return spannableBuilder;
}
Also used : SpannableBuilder(com.fastaccess.ui.widgets.SpannableBuilder) FilesListModel(com.fastaccess.data.dao.FilesListModel) NonNull(android.support.annotation.NonNull)

Example 2 with FilesListModel

use of com.fastaccess.data.dao.FilesListModel in project FastHub by k0shk0sh.

the class GistFilesListFragment method onInitFiles.

@Override
public void onInitFiles(@Nullable ArrayList<FilesListModel> filesListModel, boolean isOwner) {
    if (filesListModel == null) {
        // DO NOT PASS NULL TO ADAPTER
        filesListModel = new ArrayList<>();
    }
    if (getPresenter().getFilesMap().isEmpty()) {
        for (FilesListModel listModel : filesListModel) {
            getPresenter().getFilesMap().put(listModel.getFilename(), listModel);
        }
    }
    adapter.setOwner(isOwner);
    getPresenter().onSetList(filesListModel);
    adapter.insertItems(filesListModel);
}
Also used : FilesListModel(com.fastaccess.data.dao.FilesListModel)

Example 3 with FilesListModel

use of com.fastaccess.data.dao.FilesListModel in project FastHub by k0shk0sh.

the class GistFilesListFragment method onFileAdded.

@Override
public void onFileAdded(@NonNull FilesListModel file, Integer position) {
    if (position == null || position == -1) {
        adapter.addItem(file);
        getPresenter().getFilesMap().put(file.getFilename(), file);
    } else {
        FilesListModel current = adapter.getItem(position);
        if (getPresenter().getFilesMap().get(current.getFilename()) != null) {
            FilesListModel toUpdate = getPresenter().getFilesMap().get(current.getFilename());
            toUpdate.setFilename(file.getFilename());
            toUpdate.setContent(file.getContent());
            getPresenter().getFilesMap().put(current.getFilename(), toUpdate);
        }
        adapter.swapItem(file, position);
    }
}
Also used : FilesListModel(com.fastaccess.data.dao.FilesListModel)

Example 4 with FilesListModel

use of com.fastaccess.data.dao.FilesListModel in project FastHub by k0shk0sh.

the class GistFilesListFragment method onFragmentCreated.

@Override
protected void onFragmentCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    stateLayout.setEmptyText(R.string.no_files);
    stateLayout.showEmptyState();
    recycler.setEmptyView(stateLayout, refresh);
    refresh.setEnabled(false);
    adapter = new GistFilesAdapter(getPresenter().getFiles(), getPresenter(), isOwner);
    recycler.setAdapter(adapter);
    if (getArguments() != null && savedInstanceState == null) {
        ArrayList<FilesListModel> filesListModel = getArguments().getParcelableArrayList(BundleConstant.ITEM);
        isOwner = getArguments().getBoolean(BundleConstant.EXTRA_TYPE);
        onInitFiles(filesListModel, isOwner);
        // CLEAR
        setArguments(null);
    } else {
        onInitFiles(getPresenter().getFiles(), isOwner);
    }
    fastScroller.attachRecyclerView(recycler);
}
Also used : GistFilesAdapter(com.fastaccess.ui.adapter.GistFilesAdapter) FilesListModel(com.fastaccess.data.dao.FilesListModel)

Example 5 with FilesListModel

use of com.fastaccess.data.dao.FilesListModel in project FastHub by k0shk0sh.

the class CreateGistActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getPresenter().setEnterprise(PrefGetter.isEnterprise());
    setTaskName(getString(R.string.create_gist));
    if (savedInstanceState == null) {
        if (getIntent() != null && getIntent().getExtras() != null) {
            Bundle bundle = getIntent().getExtras();
            ArrayList<FilesListModel> models = bundle.getParcelableArrayList(BundleConstant.ITEM);
            boolean isOwner = bundle.getBoolean(BundleConstant.EXTRA);
            id = bundle.getString(BundleConstant.ID);
            String descriptionText = bundle.getString(BundleConstant.EXTRA_TWO);
            if (description.getEditText() != null)
                description.getEditText().setText(descriptionText);
            getFilesFragment().onInitFiles(models, isOwner);
        } else {
            getFilesFragment().onInitFiles(new ArrayList<>(), true);
        }
    }
    buttonsHolder.setVisibility(!InputHelper.isEmpty(id) ? View.GONE : View.VISIBLE);
}
Also used : Bundle(android.os.Bundle) FilesListModel(com.fastaccess.data.dao.FilesListModel)

Aggregations

FilesListModel (com.fastaccess.data.dao.FilesListModel)6 NonNull (android.support.annotation.NonNull)2 Bundle (android.os.Bundle)1 CreateGistModel (com.fastaccess.data.dao.CreateGistModel)1 InputHelper (com.fastaccess.helper.InputHelper)1 RestProvider (com.fastaccess.provider.rest.RestProvider)1 GistFilesAdapter (com.fastaccess.ui.adapter.GistFilesAdapter)1 BasePresenter (com.fastaccess.ui.base.mvp.presenter.BasePresenter)1 SpannableBuilder (com.fastaccess.ui.widgets.SpannableBuilder)1 HashMap (java.util.HashMap)1