Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pranjalesh committed Nov 27, 2023
1 parent fd9d9b2 commit af9a981
Showing 1 changed file with 22 additions and 95 deletions.
117 changes: 22 additions & 95 deletions src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.SearchView;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
Expand Down Expand Up @@ -113,92 +112,45 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
contentProviderUtils = new ContentProviderUtils(this);

if(getIntent().getParcelableExtra(EXTRA_TRACK_ID)!=null){
trackId = getIntent().getParcelableExtra(EXTRA_TRACK_ID);
trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback);
trackId = getIntent().getParcelableExtra(EXTRA_TRACK_ID);
if (trackId == null) {
throw new RuntimeException("TrackId is mandatory");
}
if (contentProviderUtils.getTrack(trackId) == null) {
Log.w(TAG, "TrackId does not exists.");
finish();
}


// if (trackId == null) {
// throw new RuntimeException("TrackId is mandatory");
// }
// if (contentProviderUtils.getTrack(trackId) == null) {
// Log.w(TAG, "TrackId does not exists.");
// finish();
// }


trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback);
trackDataHub = new TrackDataHub(this);

CustomFragmentPagerAdapter pagerAdapter = new CustomFragmentPagerAdapter(this);
viewBinding.trackDetailActivityViewPager.setAdapter(pagerAdapter);
// new TabLayoutMediator(viewBinding.trackDetailActivityTablayout, viewBinding.trackDetailActivityViewPager,
// (tab, position) -> tab.setText(pagerAdapter.getPageTitle(position))).attach();
// if (savedInstanceState != null) {
// viewBinding.trackDetailActivityViewPager.setCurrentItem(savedInstanceState.getInt(CURRENT_TAB_TAG_KEY));
// }

if(getIntent().getParcelableExtra(EXTRA_TRACK_ID)!=null){
viewBinding.trackRecordingFabAction.setImageResource(R.drawable.stop);
}else{
viewBinding.trackRecordingFabAction.setImageResource(R.drawable.start);
new TabLayoutMediator(viewBinding.trackDetailActivityTablayout, viewBinding.trackDetailActivityViewPager,
(tab, position) -> tab.setText(pagerAdapter.getPageTitle(position))).attach();
if (savedInstanceState != null) {
viewBinding.trackDetailActivityViewPager.setCurrentItem(savedInstanceState.getInt(CURRENT_TAB_TAG_KEY));
}

// viewBinding.holdToStopButton.setImageResource(R.drawable.ic_baseline_stop_24);
// viewBinding.holdToStopButton.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.opentracks));
// viewBinding.holdToStopButton.setBackgroundColor(ContextCompat.getColor(this, R.color.opentracks));
// viewBinding.holdToStopButton.setImageResource(R.drawable.ic_baseline_stop_24);
// viewBinding.holdToStopButton.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.opentracks));
// viewBinding.holdToStopButton.setBackgroundColor(ContextCompat.getColor(this, R.color.opentracks));
viewBinding.holdToStopButton.setOnLongClickListener((view) -> {
viewBinding.trackRecordingFabAction.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.opentracks));
viewBinding.trackRecordingFabAction.setBackgroundColor(ContextCompat.getColor(this, R.color.opentracks));
viewBinding.trackRecordingFabAction.setOnClickListener((view) -> {
ActivityUtils.vibrate(this, 1000);
trackRecordingServiceConnection.stopRecording(TrackRecordingActivity.this);
Intent newIntent = IntentUtils.newIntent(TrackRecordingActivity.this, TrackStoppedActivity.class)
.putExtra(TrackStoppedActivity.EXTRA_TRACK_ID, trackId);
startActivity(newIntent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
return true;
});
viewBinding.holdToStopButton.setOnClickListener((view) -> Toast.makeText(TrackRecordingActivity.this, getString(R.string.hold_to_pause), Toast.LENGTH_LONG).show());
viewBinding.holdToStopButton.setOnClickListener((view) -> Toast.makeText(TrackRecordingActivity.this, getString(R.string.hold_to_stop), Toast.LENGTH_LONG).show());

viewBinding.bottomAppBar.setNavigationIcon(R.drawable.ic_baseline_arrow_back_24);
setSupportActionBar(viewBinding.bottomAppBar);
setSupportActionBar(viewBinding.trackListToolbar);
viewBinding.trackRecordingFabAction.setOnClickListener(v -> startRecording(pagerAdapter));

viewBinding.trackRecordingFabAction.setOnLongClickListener((view) -> {
ActivityUtils.vibrate(this, 1000);
trackRecordingServiceConnection.stopRecording(TrackRecordingActivity.this);
Intent newIntent = IntentUtils.newIntent(TrackRecordingActivity.this, TrackStoppedActivity.class)
.putExtra(TrackStoppedActivity.EXTRA_TRACK_ID, trackId);
startActivity(newIntent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
return true;
});

}
void startRecording(CustomFragmentPagerAdapter pagerAdapter) {
if (recordingStatus.isRecording()) {
Toast.makeText(TrackRecordingActivity.this, getString(R.string.hold_to_stop), Toast.LENGTH_LONG).show();
return;
}
// Not Recording -> Recording
// updateGpsMenuItem(false, true);
new TrackRecordingServiceConnection((service, connection) -> {
trackId = service.startNewTrack();
trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback);
trackRecordingServiceConnection.startConnection(this);
}).startAndBind(this, true);

new TabLayoutMediator(viewBinding.trackDetailActivityTablayout, viewBinding.trackDetailActivityViewPager,
(tab, position) -> tab.setText(pagerAdapter.getPageTitle(position))).attach();
viewBinding.bottomAppBar.setVisibility(View.VISIBLE);

viewBinding.trackRecordingFabAction.setImageResource(R.drawable.stop);


}
@Override
public void onAttachedToWindow() {
setLockscreenPolicy();
Expand Down Expand Up @@ -256,10 +208,7 @@ protected void onStart() {

PreferencesUtils.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);

if (trackRecordingServiceConnection != null) {
trackRecordingServiceConnection.startConnection(this);
}

trackRecordingServiceConnection.startConnection(this);
trackDataHub.start();
}

Expand All @@ -276,10 +225,7 @@ protected void onResume() {
trackDataHub.setRecordingStatus(recordingStatus);
}

if (trackRecordingServiceConnection != null) {
trackRecordingServiceConnection.startAndBindWithCallback(this);
}

trackRecordingServiceConnection.startAndBindWithCallback(this);
}

@Override
Expand All @@ -288,19 +234,11 @@ protected void onSaveInstanceState(@NonNull Bundle outState) {
outState.putInt(CURRENT_TAB_TAG_KEY, viewBinding.trackDetailActivityViewPager.getCurrentItem());
}

@Override
protected void onPause() {
super.onPause();
if (trackRecordingServiceConnection != null) {
trackRecordingServiceConnection.unbind(this);
}
}

@Override
protected void onStop() {
super.onStop();
PreferencesUtils.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);

trackRecordingServiceConnection.unbind(this);
trackDataHub.stop();
}

Expand All @@ -319,7 +257,7 @@ protected View getRootView() {

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.track_menu_custom, menu);
getMenuInflater().inflate(R.menu.track_record, menu);
return super.onCreateOptionsMenu(menu);
}

Expand Down Expand Up @@ -367,17 +305,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
}

if (item.getItemId() == R.id.track_list_settings) {
startActivity(IntentUtils.newIntent(this, SettingsActivity.class));
return true;
}


if (item.getItemId() == R.id.track_list_help) {
startActivity(IntentUtils.newIntent(this, HelpActivity.class));
return true;
}

return super.onOptionsItemSelected(item);
}

Expand Down

0 comments on commit af9a981

Please sign in to comment.