Skip to content

Commit

Permalink
various changes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
zeevy committed Nov 22, 2018
1 parent dab2273 commit d731d6c
Show file tree
Hide file tree
Showing 33 changed files with 817 additions and 227 deletions.
19 changes: 15 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<uses-feature
android:name="android.hardware.usb.host"
android:required="true" />
<uses-feature android:name="android.hardware.usb.host" android:required="true" />

<application
android:name=".GrblController"
Expand All @@ -33,9 +32,14 @@
tools:targetApi="n">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" tools:targetApi="n" />

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts"
tools:targetApi="n" />
</activity>
<activity
android:name=".BluetoothConnectionActivity"
Expand Down Expand Up @@ -74,6 +78,8 @@
android:supportsPictureInPicture="false"
tools:targetApi="n" />

<activity android:name=".NotificationArchiveActivity" />

<service
android:name=".service.GrblUsbSerialService"
android:enabled="true"
Expand Down Expand Up @@ -103,6 +109,11 @@
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id" />

<meta-data android:name="DATABASE" android:value="grblcontroller.db" />
<meta-data android:name="VERSION" android:value="1" />
<meta-data android:name="QUERY_LOG" android:value="false" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="in.co.gorest.grblcontroller.model" />

</application>

</manifest>
35 changes: 4 additions & 31 deletions app/src/main/java/in/co/gorest/grblcontroller/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@

package in.co.gorest.grblcontroller;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;

import org.greenrobot.eventbus.EventBus;

import in.co.gorest.grblcontroller.events.UiToastEvent;
import in.co.gorest.grblcontroller.model.Constants;
import android.support.v7.preference.PreferenceFragmentCompat;

public class AboutActivity extends AppCompatActivity {

Expand All @@ -42,10 +37,10 @@ public class AboutActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getSupportActionBar() != null) getSupportActionBar().setSubtitle(getString(R.string.text_app_about));
getFragmentManager().beginTransaction().replace(android.R.id.content, new AppAboutFragment()).commit();
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, new AppAboutFragment()).commit();
}

public static class AppAboutFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener{
public static class AppAboutFragment extends PreferenceFragmentCompat {

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -56,32 +51,10 @@ public void onCreate(Bundle savedInstanceState) {
}

@Override
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
public void onCreatePreferences(Bundle bundle, String s) {

@Override
public void onPause() {
super.onPause();
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

if(key.equals(getString(R.string.preference_default_serial_connection_type))){
EventBus.getDefault().post(new UiToastEvent("Application restart required"));
}

if(key.equalsIgnoreCase(getString(R.string.preference_gcode_file_picker_type))){
String value = sharedPreferences.getString(key, "");
if(value.equalsIgnoreCase("full")){
EventBus.getDefault().post(new UiToastEvent(getString(R.string.text_only_internal_storage_supported)));
}
}

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
import android.view.Menu;
import android.view.MenuItem;

import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.joanzapata.iconify.IconDrawable;
import com.joanzapata.iconify.fonts.FontAwesomeIcons;

Expand All @@ -53,7 +50,6 @@
import in.co.gorest.grblcontroller.events.BluetoothDisconnectEvent;
import in.co.gorest.grblcontroller.events.GrblSettingMessageEvent;
import in.co.gorest.grblcontroller.events.JogCommandEvent;
import in.co.gorest.grblcontroller.events.StreamingCompleteEvent;
import in.co.gorest.grblcontroller.events.UiToastEvent;
import in.co.gorest.grblcontroller.listeners.MachineStatusListener;
import in.co.gorest.grblcontroller.model.Constants;
Expand Down Expand Up @@ -284,7 +280,6 @@ private void onBluetoothStateChange(int currentState){
switch (currentState){
case GrblBluetoothSerialService.STATE_CONNECTED:
if(getSupportActionBar() != null) getSupportActionBar().setSubtitle((mConnectedDeviceName != null) ? mConnectedDeviceName : getString(R.string.text_connected));
Answers.getInstance().logCustom(new CustomEvent("Connection Type").putCustomAttribute("Connection", "Bluetooth"));
invalidateOptionsMenu();
break;
case GrblBluetoothSerialService.STATE_CONNECTING:
Expand Down Expand Up @@ -350,8 +345,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
connectToDevice(macAddress);
}

}catch (NullPointerException e){
Crashlytics.logException(e);
}catch (NullPointerException ignored){

}
}
}
Expand Down
33 changes: 16 additions & 17 deletions app/src/main/java/in/co/gorest/grblcontroller/GrblActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package in.co.gorest.grblcontroller;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
Expand All @@ -47,7 +48,6 @@
import android.view.View;
import android.widget.Toast;

import com.crashlytics.android.Crashlytics;
import com.joanzapata.iconify.IconDrawable;
import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.fonts.FontAwesomeIcons;
Expand All @@ -68,13 +68,11 @@
import in.co.gorest.grblcontroller.listeners.ConsoleLoggerListener;
import in.co.gorest.grblcontroller.listeners.FileSenderListener;
import in.co.gorest.grblcontroller.listeners.MachineStatusListener;
import in.co.gorest.grblcontroller.model.Constants;
import in.co.gorest.grblcontroller.service.FileStreamerIntentService;
import in.co.gorest.grblcontroller.service.GrblBluetoothSerialService;
import in.co.gorest.grblcontroller.service.MyFirebaseInstanceIDService;
import in.co.gorest.grblcontroller.ui.BaseFragment;
import in.co.gorest.grblcontroller.ui.GrblFragmentPagerAdapter;
import in.co.gorest.grblcontroller.util.GrblUtils;

public abstract class GrblActivity extends AppCompatActivity implements BaseFragment.OnFragmentInteractionListener{

Expand Down Expand Up @@ -118,7 +116,7 @@ public boolean onLongClick(View view) {
});

Iconify.with(new FontAwesomeModule());
setupTabLayout(R.id.tab_layout, R.id.tab_layout_pager);
setupTabLayout();
checkPowerManagement();

String fcmToken = sharedPref.getString(getString(R.string.firebase_cloud_messaging_token), null);
Expand All @@ -144,8 +142,8 @@ public void onDestroy(){

public void freeAppNotification(){
new AlertDialog.Builder(this)
.setTitle("Free Application")
.setMessage("You are using free version of the application. \nIf you would like to support the app development or want to donate, please purchase the Grbl Controller +\nPaid version contains most up to date features and enhancements")
.setTitle("Grbl Controller")
.setMessage("Hello you are using free basic version of the application. For more exiting features buy Grbl Controller +")
.setPositiveButton("Purchase", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
try {
Expand Down Expand Up @@ -182,12 +180,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
return true;

case R.id.app_notifications:
startActivity(new Intent(getApplicationContext(), NotificationArchiveActivity.class));
return true;

case R.id.app_about:
startActivity(new Intent(getApplicationContext(), AboutActivity.class));
return true;

case R.id.share:

try {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
Expand All @@ -197,7 +198,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
startActivity(Intent.createChooser(sharingIntent, "Sharing Option"));
}catch (ActivityNotFoundException e){
Crashlytics.logException(e);
grblToast("No application available to perform this action!");
}

Expand All @@ -219,8 +219,8 @@ protected void applicationSetup(){

}

protected void setupTabLayout(int tabLayoutId, int tabLayoutPagerId){
TabLayout tabLayout = findViewById(tabLayoutId);
protected void setupTabLayout(){
TabLayout tabLayout = findViewById(R.id.tab_layout);

if(isTablet(this)){
tabLayout.addTab(tabLayout.newTab().setIcon(new IconDrawable(this, FontAwesomeIcons.fa_arrows_alt).colorRes(R.color.colorAccent).sizeDp(32)));
Expand All @@ -237,7 +237,7 @@ protected void setupTabLayout(int tabLayoutId, int tabLayoutPagerId){

tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

final ViewPager viewPager = findViewById(tabLayoutPagerId);
final ViewPager viewPager = findViewById(R.id.tab_layout_pager);
final GrblFragmentPagerAdapter pagerAdapter = new GrblFragmentPagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(pagerAdapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
Expand All @@ -257,6 +257,7 @@ public void onTabReselected(TabLayout.Tab tab) {}
});
}

@SuppressLint("ShowToast")
protected void grblToast(String message){

if(toastMessage == null){
Expand Down Expand Up @@ -290,17 +291,15 @@ private void checkPowerManagement(){
if(pm != null && !pm.isIgnoringBatteryOptimizations(getPackageName())){

new AlertDialog.Builder(this)
.setTitle("Warning! battery optimisation is enabled")
.setMessage("For long running jobs, disable android battery optimisation for this application.")
.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
.setTitle(getString(R.string.text_power_management_warning_title))
.setMessage(getString(R.string.text_power_management_warning_description))
.setPositiveButton(getString(R.string.text_settings), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
try {
Intent myIntent = new Intent();
myIntent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
startActivity(myIntent);
} catch (RuntimeException e) {
Crashlytics.logException(e);
}
} catch (RuntimeException ignored) {}
}
})
.setNegativeButton(getString(R.string.text_cancel), null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@
import android.app.Application;
import android.support.v7.app.AppCompatDelegate;

import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.core.CrashlyticsCore;
import com.orm.SugarApp;

import in.co.gorest.grblcontroller.network.GoRestService;
import io.fabric.sdk.android.Fabric;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class GrblController extends Application {
public class GrblController extends SugarApp {

private final String TAG = GrblController.class.getSimpleName();
private static GrblController grblController;
Expand Down Expand Up @@ -63,8 +60,7 @@ public static synchronized GrblController getInstance(){
}

private void configureCrashReporting(){
CrashlyticsCore crashlyticsCore = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
Fabric.with(this, new Crashlytics.Builder().core(crashlyticsCore).build(), new Answers());

}

public GoRestService getRetrofit(){
Expand Down
Loading

0 comments on commit d731d6c

Please sign in to comment.