Skip to content
Snippets Groups Projects
Commit acf7e6a5 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Added event for init data progress

parent af8565ad
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ import java.util.Map;
import de.kuschku.libquassel.BusProvider;
import de.kuschku.libquassel.events.ConnectionChangeEvent;
import de.kuschku.libquassel.events.CriticalErrorEvent;
import de.kuschku.libquassel.events.InitEvent;
import de.kuschku.libquassel.events.LagChangedEvent;
import de.kuschku.libquassel.events.PasswordChangeEvent;
import de.kuschku.libquassel.events.StatusMessageEvent;
......@@ -84,6 +85,7 @@ public class Client extends AClient {
private final QBacklogManager<? extends QBacklogManager> backlogManager;
private final Map<String, List<SyncFunction>> bufferedSyncs = new HashMap<>();
private final Map<Integer, Pair<QBufferViewConfig, Integer>> bufferedBuffers = new HashMap<>();
private int initRequestMax = 0;
private QBufferViewManager bufferViewManager;
// local
private QBufferSyncer bufferSyncer;
......@@ -336,8 +338,10 @@ public class Client extends AClient {
public void requestInitObject(@NonNull String className, String objectName) {
assertNotNull(provider);
if (connectionStatus() == ConnectionChangeEvent.Status.INITIALIZING_DATA)
if (connectionStatus() == ConnectionChangeEvent.Status.INITIALIZING_DATA) {
initRequests.add(hashName(className, objectName));
initRequestMax++;
}
provider.dispatch(new InitRequestFunction(className, objectName));
}
......@@ -347,6 +351,7 @@ public class Client extends AClient {
if (connectionStatus() == ConnectionChangeEvent.Status.INITIALIZING_DATA) {
initRequests.remove(hashName(className, objectName));
provider.sendEvent(new InitEvent(initRequestMax - initRequests.size(), initRequestMax));
if (initRequests.isEmpty()) {
setConnectionStatus(ConnectionChangeEvent.Status.LOADING_BACKLOG);
}
......
......@@ -25,15 +25,15 @@ import java.util.Locale;
public class BacklogInitEvent {
public final int loaded;
public final int waitingMax;
public final int max;
public BacklogInitEvent(int loaded, int waitingMax) {
public BacklogInitEvent(int loaded, int max) {
this.loaded = loaded;
this.waitingMax = waitingMax;
this.max = max;
}
@Override
public String toString() {
return String.format(Locale.US, "LOADING_BACKLOG: %d/%d", loaded, waitingMax);
return String.format(Locale.US, "LOADING_BACKLOG: %d/%d", loaded, max);
}
}
/*
* QuasselDroid - Quassel client for Android
* Copyright (C) 2016 Janne Koschinski
* Copyright (C) 2016 Ken Børge Viktil
* Copyright (C) 2016 Magnus Fjell
* Copyright (C) 2016 Martin Sandsmark <martin.sandsmark@kde.org>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.events;
import java.util.Locale;
public class InitEvent {
public final int loaded;
public final int max;
public InitEvent(int loaded, int max) {
this.loaded = loaded;
this.max = max;
}
@Override
public String toString() {
return String.format(Locale.US, "INITIALIZING_DATA: %d/%d", loaded, max);
}
}
......@@ -32,7 +32,6 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.design.widget.Snackbar;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ActionMenuView;
......@@ -42,7 +41,6 @@ import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.SpannableString;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
......@@ -81,13 +79,13 @@ import de.kuschku.libquassel.events.BacklogInitEvent;
import de.kuschku.libquassel.events.BacklogReceivedEvent;
import de.kuschku.libquassel.events.ConnectionChangeEvent;
import de.kuschku.libquassel.events.GeneralErrorEvent;
import de.kuschku.libquassel.events.InitEvent;
import de.kuschku.libquassel.events.LagChangedEvent;
import de.kuschku.libquassel.events.LoginRequireEvent;
import de.kuschku.libquassel.events.UnknownCertificateEvent;
import de.kuschku.libquassel.localtypes.BacklogFilter;
import de.kuschku.libquassel.localtypes.buffers.Buffer;
import de.kuschku.libquassel.localtypes.buffers.ChannelBuffer;
import de.kuschku.libquassel.localtypes.buffers.QueryBuffer;
import de.kuschku.libquassel.message.Message;
import de.kuschku.libquassel.syncables.types.interfaces.QBufferViewConfig;
import de.kuschku.libquassel.syncables.types.interfaces.QBufferViewManager;
......@@ -111,7 +109,6 @@ import de.kuschku.util.instancestateutil.Storable;
import de.kuschku.util.instancestateutil.Store;
import de.kuschku.util.observables.AutoScroller;
import de.kuschku.util.observables.lists.ObservableSortedList;
import de.kuschku.util.ui.MessageUtil;
import static de.kuschku.util.AndroidAssert.assertNotNull;
......@@ -191,6 +188,24 @@ public class ChatActivity extends AppCompatActivity {
}
};
private static void updateNoColor(Buffer buffer, @NonNull Menu menu) {
boolean isNoColor = isNoColor(buffer);
menu.findItem(R.id.format_bold).setEnabled(!isNoColor);
menu.findItem(R.id.format_italic).setEnabled(!isNoColor);
menu.findItem(R.id.format_underline).setEnabled(!isNoColor);
menu.findItem(R.id.format_paint).setEnabled(!isNoColor);
menu.findItem(R.id.format_fill).setEnabled(!isNoColor);
}
public static boolean isNoColor(Buffer buffer) {
if (buffer == null)
return false;
if (!(buffer instanceof ChannelBuffer))
return false;
QIrcChannel channel = ((ChannelBuffer) buffer).getChannel();
return channel != null && channel.hasMode('c');
}
private void updateSubTitle() {
if (context.client() != null) {
if (context.client().connectionStatus() == ConnectionChangeEvent.Status.CONNECTED) {
......@@ -212,24 +227,6 @@ public class ChatActivity extends AppCompatActivity {
updateSubTitle("");
}
private static void updateNoColor(Buffer buffer, @NonNull Menu menu) {
boolean isNoColor = isNoColor(buffer);
menu.findItem(R.id.format_bold).setEnabled(!isNoColor);
menu.findItem(R.id.format_italic).setEnabled(!isNoColor);
menu.findItem(R.id.format_underline).setEnabled(!isNoColor);
menu.findItem(R.id.format_paint).setEnabled(!isNoColor);
menu.findItem(R.id.format_fill).setEnabled(!isNoColor);
}
public static boolean isNoColor(Buffer buffer) {
if (buffer == null)
return false;
if (!(buffer instanceof ChannelBuffer))
return false;
QIrcChannel channel = ((ChannelBuffer) buffer).getChannel();
return channel != null && channel.hasMode('c');
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
setupContext();
......@@ -690,6 +687,10 @@ public class ChatActivity extends AppCompatActivity {
updateSubTitle(event.toString());
}
public void onEventMainThread(@NonNull InitEvent event) {
updateSubTitle(event.toString());
}
private void updateBufferViewConfigs() {
assertNotNull(context.client().bufferViewManager());
List<QBufferViewConfig> bufferViews = context.client().bufferViewManager().bufferViewConfigs();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment