@Override public void onDestroy() { super.onDestroy(); // Make sure our notification is gone. hideNotification(); Log.i(Globals.LOG_TAG, "MumbleService: Destroyed"); dbAdapter.close(); }
@Override public void onCreate() { super.onCreate(); // Make sure our notification is gone. hideNotification(); settings = Settings.getInstance(this); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "plumbleLock"); Log.i(Globals.LOG_TAG, "MumbleService: Created"); serviceState = CONNECTION_STATE_DISCONNECTED; chatFormatter = new PlumbleChatFormatter(this); dbAdapter = new DbAdapter(this); dbAdapter.open(); }
public void updateFavourites() { DbAdapter dbAdapter = getDatabaseAdapter(); favourites = dbAdapter.fetchAllFavourites(getConnectedServer().getId()); }
private final void refreshElements(final View view, final User user) { // If this view has been used for another user already, don't update // it with the information from this user. if ((Integer) view.getTag() != user.session) { return; } final TextView name = (TextView) view.findViewById(R.id.userRowName); final ImageView state = (ImageView) view.findViewById(R.id.userRowState); final ImageView comment = (ImageView) view.findViewById(R.id.commentState); final ImageView localMute = (ImageView) view.findViewById(R.id.localMuteState); final ImageView chatActive = (ImageView) view.findViewById(R.id.activeChatState); name.setText(user.name); switch (user.userState) { case User.USERSTATE_DEAFENED: state.setImageResource(R.drawable.ic_deafened); break; case User.USERSTATE_MUTED: state.setImageResource(R.drawable.ic_muted); break; default: if (user.talkingState == AudioOutputHost.STATE_TALKING) { state.setImageResource(R.drawable.ic_talking_on); } else { state.setImageResource(R.drawable.ic_talking_off); } } localMute.setVisibility(user.localMuted ? View.VISIBLE : View.GONE); if (user.comment != null || user.commentHash != null) { // Ask the DB whether the user's comment has been seen or not. dbAdapter.open(); boolean commentSeen = dbAdapter.isCommentSeen( user.name, user.commentHash != null ? user.commentHash.toStringUtf8() : user.comment); comment.setImageResource(commentSeen ? R.drawable.ic_comment_seen : R.drawable.ic_comment); dbAdapter.close(); } comment.setVisibility( user.comment != null || user.commentHash != null ? View.VISIBLE : View.GONE); comment.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (user.comment != null || user.commentHash != null) { comment.setImageResource(R.drawable.ic_comment_seen); dbAdapter.open(); dbAdapter.setCommentSeen( user.name, user.commentHash != null ? user.commentHash.toStringUtf8() : user.comment); dbAdapter.close(); } AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Comment"); builder.setPositiveButton("Close", null); final WebView webView = new WebView(context); webView.loadDataWithBaseURL( "", "<center>Retrieving...</center>", "text/html", "utf-8", ""); builder.setView(webView); final AlertDialog dialog = builder.show(); if (user.comment != null) { webView.loadDataWithBaseURL("", user.comment, "text/html", "utf-8", ""); } else if (user.commentHash != null) { // Retrieve comment from blob final RequestBlob.Builder blobBuilder = RequestBlob.newBuilder(); blobBuilder.addSessionComment(user.session); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { MumbleService.getCurrentService() .sendTcpMessage(MessageType.RequestBlob, blobBuilder); // TODO fix. This is messy, we're polling until we get a comment response. while (user.comment == null && dialog.isShowing()) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } protected void onPostExecute(Void result) { webView.loadDataWithBaseURL("", user.comment, "text/html", "utf-8", ""); }; }.execute(); } } }); chatActive.setImageDrawable(chatDrawable); chatActive.setVisibility(user.equals(selectedUser) ? View.VISIBLE : View.GONE); view.invalidate(); }