Search in sources :

Example 1 with ServerRecAdapter

use of ar.rulosoft.mimanganu.adapters.ServerRecAdapter in project MiMangaNu by raulhaag.

the class ServersSelectFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    SharedPreferences pm = PreferenceManager.getDefaultSharedPreferences(getActivity());
    ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_add_manga, container, false);
    server_list = viewGroup.findViewById(R.id.lista_de_servers);
    server_list.setLayoutManager(new LinearLayoutManager(getActivity()));
    serverRecAdapter = new ServerRecAdapter(ServerBase.getServers(getContext()), pm, getActivity());
    serverRecAdapter.setEndActionModeListener(this);
    server_list.setAdapter(serverRecAdapter);
    serverRecAdapter.setOnServerClickListener(new ServerRecAdapter.OnServerClickListener() {

        @Override
        public void onServerClick(final ServerBase server) {
            if (!(server instanceof FromFolder)) {
                if (server.hasCredentials()) {
                    if (server.hasFilteredNavigation()) {
                        ServerFilteredNavigationFragment fragment = new ServerFilteredNavigationFragment();
                        Bundle b = new Bundle();
                        b.putInt(MainFragment.SERVER_ID, server.getServerID());
                        fragment.setArguments(b);
                        ((MainActivity) getActivity()).replaceFragment(fragment, "FilteredNavigation");
                    } else {
                        ServerListFragment fragment = new ServerListFragment();
                        Bundle b = new Bundle();
                        b.putInt(MainFragment.SERVER_ID, server.getServerID());
                        fragment.setArguments(b);
                        ((MainActivity) getActivity()).replaceFragment(fragment, "FilteredServerList");
                    }
                } else {
                    LoginDialog lDialog = new LoginDialog(getContext(), server);
                    lDialog.getDialog().setCanceledOnTouchOutside(false);
                    lDialog.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            if (server.hasCredentials())
                                onServerClick(server);
                            else
                                Util.getInstance().showFastSnackBar(getString(R.string.this_server_needs_an_account), getView(), getContext());
                        }
                    });
                    lDialog.show();
                }
            } else {
                MangaFolderSelect mangaFolderSelect = new MangaFolderSelect();
                mangaFolderSelect.show(getChildFragmentManager(), "fragment_find_folder");
            }
        }
    });
    return viewGroup;
}
Also used : ServerBase(ar.rulosoft.mimanganu.servers.ServerBase) FromFolder(ar.rulosoft.mimanganu.servers.FromFolder) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) MangaFolderSelect(ar.rulosoft.mimanganu.componentes.MangaFolderSelect) ViewGroup(android.view.ViewGroup) Bundle(android.os.Bundle) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ServerRecAdapter(ar.rulosoft.mimanganu.adapters.ServerRecAdapter) LoginDialog(ar.rulosoft.mimanganu.componentes.LoginDialog)

Aggregations

DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 ViewGroup (android.view.ViewGroup)1 ServerRecAdapter (ar.rulosoft.mimanganu.adapters.ServerRecAdapter)1 LoginDialog (ar.rulosoft.mimanganu.componentes.LoginDialog)1 MangaFolderSelect (ar.rulosoft.mimanganu.componentes.MangaFolderSelect)1 FromFolder (ar.rulosoft.mimanganu.servers.FromFolder)1 ServerBase (ar.rulosoft.mimanganu.servers.ServerBase)1