Skip to content

Commit

Permalink
Fix bug with some IP addresses unable to start streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrivoruchko committed Sep 29, 2016
1 parent bcebb8a commit f55996e
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 22 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "info.dvkr.screenstream"
minSdkVersion 21
targetSdkVersion 24
versionCode 14
versionName "1.1.7"
versionCode 15
versionName "1.1.8"
resConfigs "en", "ru"
}

Expand Down Expand Up @@ -37,7 +37,7 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:design:24.2.1'
compile 'com.google.firebase:firebase-crash:9.4.0'
compile 'com.google.firebase:firebase-crash:9.6.0'
compile 'org.greenrobot:eventbus:3.0.0'
}

Expand Down
6 changes: 1 addition & 5 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#}

# EventBus 3.0
-keepclassmembers class ** {
public void onMessageEvent*(**);
}

# EventBus 3.0 annotation
-keepattributes *Annotation*
-keepclassmembers class * {
@org.greenrobot.eventbus.Subscribe <methods>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
import info.dvkr.screenstream.data.AppData;
import info.dvkr.screenstream.data.local.PreferencesHelper;
import info.dvkr.screenstream.service.ForegroundService;
import info.dvkr.screenstream.viewModel.MainActivityViewModel;
import info.dvkr.screenstream.viewmodel.MainActivityViewModel;


public class ScreenStreamApplication extends Application {
private static ScreenStreamApplication sAppInstance;

private AppData mAppData;
private MainActivityViewModel mMainActivityViewModel;
private PreferencesHelper mPreferencesHelper;
private AppData mAppData;

@Override
public void onCreate() {
super.onCreate();
sAppInstance = this;

mAppData = new AppData(this);
mMainActivityViewModel = new MainActivityViewModel(this);
mPreferencesHelper = new PreferencesHelper(this);
mAppData = new AppData(this);

startService(ForegroundService.getStartIntent(this));
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/info/dvkr/screenstream/data/AppData.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public String getServerAddress() {
}

public boolean isWiFiConnected() {
return mWifiManager.getConnectionInfo().getIpAddress() > 0;
return mWifiManager.getConnectionInfo().getIpAddress() != 0;
}

//Private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public final class ForegroundService extends Service {
private HttpServer mHttpServer;
private ImageGenerator mImageGenerator;
private NotifyImageGenerator mNotifyImageGenerator;
private HandlerThread mHandlerThread;
private ForegroundServiceHandler mForegroundServiceTaskHandler;
private BroadcastReceiver mLocalNotificationReceiver;
private BroadcastReceiver mBroadcastReceiver;
Expand Down Expand Up @@ -107,10 +108,11 @@ public void onStop() {
mNotifyImageGenerator.addDefaultScreen();

// Starting thread Handler
final HandlerThread looperThread =
new HandlerThread(ForegroundService.class.getSimpleName(), Process.THREAD_PRIORITY_MORE_FAVORABLE);
looperThread.start();
mForegroundServiceTaskHandler = new ForegroundServiceHandler(looperThread.getLooper());
mHandlerThread = new HandlerThread(
ForegroundService.class.getSimpleName(),
Process.THREAD_PRIORITY_MORE_FAVORABLE);
mHandlerThread.start();
mForegroundServiceTaskHandler = new ForegroundServiceHandler(mHandlerThread.getLooper());

//Local notifications
final IntentFilter localNotificationIntentFilter = new IntentFilter();
Expand Down Expand Up @@ -200,7 +202,7 @@ public void onDestroy() {
unregisterReceiver(mBroadcastReceiver);
unregisterReceiver(mLocalNotificationReceiver);
if (mMediaProjection != null) mMediaProjection.unregisterCallback(mProjectionCallback);
mForegroundServiceTaskHandler.getLooper().quit();
mHandlerThread.quit();
}

@Subscribe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.greenrobot.eventbus.ThreadMode;

import info.dvkr.screenstream.R;
import info.dvkr.screenstream.data.AppData;
import info.dvkr.screenstream.data.BusMessages;
import info.dvkr.screenstream.databinding.ActivityMainBinding;
import info.dvkr.screenstream.service.ForegroundService;
Expand Down Expand Up @@ -84,7 +85,6 @@ protected void onStart() {
getAppData().setActivityRunning(true);
}


@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onMessageEvent(BusMessages busMessage) {
switch (busMessage.getMessage()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.dvkr.screenstream.viewModel;
package info.dvkr.screenstream.viewmodel;

import android.content.Context;
import android.databinding.BaseObservable;
Expand Down Expand Up @@ -138,7 +138,7 @@ public String getConnectedClientsText() {
}

public void onToggleButtonClick(View v) {
if (getAppData().isStreamRunning()) {
if (mIsStreaming) {
EventBus.getDefault().post(new BusMessages(BusMessages.MESSAGE_ACTION_STREAMING_STOP));
} else {
((ToggleButton) v).setChecked(false);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<variable
name="viewModel"
type="info.dvkr.screenstream.viewModel.MainActivityViewModel"/>
type="info.dvkr.screenstream.viewmodel.MainActivityViewModel"/>
</data>

<LinearLayout android:id="@+id/layout_main_view"
Expand Down Expand Up @@ -63,6 +63,7 @@
</LinearLayout>

<ToggleButton
android:id="@+id/btn_start_stream"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-rc1'
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.0.0'

// NOTE: Do not place your application dependencies here; they belong
Expand Down

0 comments on commit f55996e

Please sign in to comment.