Search in sources :

Example 1 with User

use of se.oort.diplicity.apigen.User in project android-diplicity by zond.

the class MainActivity method onResume.

@Override
public void onResume() {
    super.onResume();
    if (ACTION_VIEW_USER_GAMES.equals(getIntent().getAction())) {
        byte[] serializedUser = getIntent().getByteArrayExtra(SERIALIZED_USER_KEY);
        if (serializedUser != null) {
            User user = (User) unserialize(serializedUser);
            displayUserGames(user, getIntent().getStringExtra(GAME_STATE_KEY));
        }
    } else if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
        Uri uri = getIntent().getData();
        Matcher m = viewGamePattern.matcher(uri.getPath());
        if (m.matches()) {
            displaySingleGame(m.group(1));
        }
    }
}
Also used : User(se.oort.diplicity.apigen.User) Matcher(java.util.regex.Matcher) Uri(android.net.Uri)

Example 2 with User

use of se.oort.diplicity.apigen.User in project android-diplicity by zond.

the class MainActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        Intent i = new Intent(this, PreferenceActivity.class);
        startActivity(i);
        return true;
    } else if (id == R.id.action_error_log) {
        AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setView(R.layout.error_log_dialog).show();
        ((EditText) dialog.findViewById(R.id.error_log)).setText(App.errorLog.toString());
    } else if (id == R.id.action_forum) {
        String url = "https://groups.google.com/forum/#!forum/diplicity-talk";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    } else if (id == R.id.action_source) {
        String url = "https://github.com/zond/android-diplicity";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    } else if (id == R.id.action_alarms) {
        AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setView(R.layout.alarms_dialog).show();
        Map<String, ?> alarms = Alarm.getAlarmPreferences(this).getAll();
        LinearLayout layout = (LinearLayout) dialog.findViewById(R.id.alarms_list);
        if (alarms.size() == 0) {
            dialog.findViewById(R.id.empty_view).setVisibility(View.VISIBLE);
            layout.setVisibility(View.GONE);
        } else {
            dialog.findViewById(R.id.empty_view).setVisibility(View.GONE);
            for (Object json : Alarm.getAlarmPreferences(this).getAll().values()) {
                Alarm.Alert alert = Alarm.Alert.fromJSON("" + json);
                LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View row = inflater.inflate(R.layout.alarm_list_row, null);
                ((TextView) row.findViewById(R.id.desc)).setText(alert.desc);
                ((TextView) row.findViewById(R.id.at)).setText(alert.alertAt(this).toString());
                layout.addView(row);
            }
            layout.setVisibility(View.VISIBLE);
        }
    } else if (id == R.id.action_bans) {
        handleReq(banService.ListBans(getLoggedInUser().Id), new Sendable<MultiContainer<Ban>>() {

            private RelativeLayout.LayoutParams wrapContentParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

            private void setMargins(RelativeLayout.LayoutParams params) {
                int margin = getResources().getDimensionPixelSize(R.dimen.member_table_margin);
                params.bottomMargin = margin;
                params.topMargin = margin;
                params.leftMargin = margin;
                params.rightMargin = margin;
            }

            private void setupView(final AlertDialog dialog, final MultiContainer<Ban> banMultiContainer, final SingleContainer<Ban> ban, View convertView) {
                User other = null;
                for (User u : ban.Properties.Users) {
                    if (!u.Id.equals(getLoggedInUser().Id)) {
                        other = u;
                        break;
                    }
                }
                if (other != null) {
                    final User finalOther = other;
                    ((UserView) convertView.findViewById(R.id.other_user)).setUser(MainActivity.this, other, true);
                    if (ban.Properties.OwnerIds.contains(getLoggedInUser().Id)) {
                        LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        FloatingActionButton button = (FloatingActionButton) inflater.inflate(R.layout.clear_button, null);
                        setMargins(wrapContentParams);
                        wrapContentParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                        wrapContentParams.addRule(RelativeLayout.ALIGN_PARENT_END);
                        wrapContentParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                        button.setLayoutParams(wrapContentParams);
                        button.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                handleReq(banService.BanDelete(getLoggedInUser().Id, finalOther.Id), new Sendable<SingleContainer<Ban>>() {

                                    @Override
                                    public void send(SingleContainer<Ban> banSingleContainer) {
                                        ban.Properties.OwnerIds.remove(getLoggedInUser().Id);
                                        if (ban.Properties.OwnerIds.isEmpty()) {
                                            banMultiContainer.Properties.remove(ban);
                                        }
                                        setupDialog(dialog, banMultiContainer);
                                    }
                                }, getResources().getString(R.string.updating));
                            }
                        });
                        ((RelativeLayout) convertView.findViewById(R.id.ban_list_row_layout)).addView(button);
                    }
                }
            }

            @Override
            public void send(MultiContainer<Ban> banMultiContainer) {
                AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setView(R.layout.bans_dialog).show();
                setupDialog(dialog, banMultiContainer);
            }

            private void setupDialog(AlertDialog dialog, MultiContainer<Ban> banMultiContainer) {
                List<SingleContainer<Ban>> asBannerList = new ArrayList<>();
                List<SingleContainer<Ban>> asBannedList = new ArrayList<>();
                for (SingleContainer<Ban> banSingleContainer : banMultiContainer.Properties) {
                    if (banSingleContainer.Properties.OwnerIds.contains(getLoggedInUser().Id)) {
                        asBannerList.add(banSingleContainer);
                    } else {
                        asBannedList.add(banSingleContainer);
                    }
                }
                ViewGroup parent = (ViewGroup) dialog.findViewById(R.id.bans_dialog_layout);
                LinearLayout asBanner = (LinearLayout) dialog.findViewById(R.id.hater_list);
                if (asBannerList.isEmpty()) {
                    dialog.findViewById(R.id.as_banner_no_data).setVisibility(View.VISIBLE);
                    asBanner.setVisibility(View.GONE);
                } else {
                    dialog.findViewById(R.id.as_banner_no_data).setVisibility(View.GONE);
                    asBanner.removeAllViews();
                    for (SingleContainer<Ban> ban : asBannerList) {
                        View itemView = LayoutInflater.from(MainActivity.this).inflate(R.layout.ban_list_row, parent, false);
                        asBanner.addView(itemView);
                        setupView(dialog, banMultiContainer, ban, itemView);
                    }
                }
                LinearLayout asBanned = (LinearLayout) dialog.findViewById(R.id.hated_list);
                if (asBannedList.isEmpty()) {
                    dialog.findViewById(R.id.as_banned_no_data).setVisibility(View.VISIBLE);
                    asBanned.setVisibility(View.GONE);
                } else {
                    dialog.findViewById(R.id.as_banner_no_data).setVisibility(View.GONE);
                    asBanned.removeAllViews();
                    for (SingleContainer<Ban> ban : asBannedList) {
                        View itemView = LayoutInflater.from(MainActivity.this).inflate(R.layout.ban_list_row, parent, false);
                        asBanned.addView(itemView);
                        setupView(dialog, banMultiContainer, ban, itemView);
                    }
                }
            }
        }, getResources().getString(R.string.loading_bans));
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) User(se.oort.diplicity.apigen.User) ArrayList(java.util.ArrayList) MultiContainer(se.oort.diplicity.apigen.MultiContainer) FloatingActionButton(android.support.design.widget.FloatingActionButton) TextView(android.widget.TextView) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ExpandableListView(android.widget.ExpandableListView) Ban(se.oort.diplicity.apigen.Ban) SingleContainer(se.oort.diplicity.apigen.SingleContainer) LayoutInflater(android.view.LayoutInflater) RelativeLayout(android.widget.RelativeLayout) LinearLayout(android.widget.LinearLayout)

Aggregations

User (se.oort.diplicity.apigen.User)2 Intent (android.content.Intent)1 Uri (android.net.Uri)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 AlertDialog (android.support.v7.app.AlertDialog)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 ExpandableListView (android.widget.ExpandableListView)1 LinearLayout (android.widget.LinearLayout)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Ban (se.oort.diplicity.apigen.Ban)1 MultiContainer (se.oort.diplicity.apigen.MultiContainer)1 SingleContainer (se.oort.diplicity.apigen.SingleContainer)1