2
\$\begingroup\$

I have created a yoga app on Android Studio. Can someone review the code to see if I have used the best practices of programming?

MainActivity:

package mo.youga;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardedVideoAd;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;


public class MainActivity extends AppCompatActivity {


    //GOOGLE AD MOB
    private RewardedVideoAd RewardedVideoAd;
    //GOOGLE AD MOB

    Button Poses,Setting,Calendar;
    ImageView Training;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Poses=(Button)findViewById(R.id.Poses);
        Setting=(Button)findViewById(R.id.Setting);
        Training=(ImageView)findViewById(R.id.Training);
        Calendar=(Button)findViewById(R.id.Calendar);


        //listener for calendar
        Calendar.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                Intent intent= new Intent(MainActivity.this,Calendar.class);
                startActivity(intent);
            }


        });



        //listener for training
        Training.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                Intent intent= new Intent(MainActivity.this,DailyTraining.class);
                startActivity(intent);
            }


        });


        //listener for setting
        Setting.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view){
            Intent intent= new Intent(MainActivity.this,Setting.class);
            startActivity(intent);
            }
        });


        //listener for poses
        Poses.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view){
            Intent intent= new Intent(MainActivity.this,ListOfPoses.class);
            startActivity(intent);
            }
        });
/*
***********************************************************************************************************
* *********************************************************************************************************
* *********************************************************************************************************
* *********************************************************************************************************
 */
        //THIS IS GOOGLE AD MOBS FIX THIS

        //  AdMob app ID: ca-app-pub-4935262637979763~8258229167
        MobileAds.initialize(this, "ca-app-pub-4935262637979763~8258229167");

        // Use an activity context to get the rewarded video instance.
        RewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
        RewardedVideoAd.setRewardedVideoAdListener((RewardedVideoAdListener) this);

        //LOAD REWARDED VIDEO AD
        loadRewardedVideoAd();



    }

    //GOOGLE ADS USE THIS
    //LOAD REWARDED VIDEO ADVERT AD MOB
    private void loadRewardedVideoAd() {
        RewardedVideoAd.loadAd("ca-app-pub-4935262637979763/2567026581",
                new AdRequest.Builder().build());
    }//END




}

Setting:

package mo.youga;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.annotation.IdRes;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.ToggleButton;
//IMPORTING FROM OWN PACKAGE
import java.util.Calendar;
import java.util.Date;
import java.util.*;
import java.io.*;

import mo.youga.Database.YougaDB;

import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;



public class Setting extends AppCompatActivity {

    Button Save;
    RadioButton Easy, Intermediate, Difficult;
    RadioGroup Group;
    YougaDB yougaDB;
    ToggleButton switchAlarm;
    TimePicker timePicker;

    /*
   protected <T extends View> T findViewById(@IdRes int id) {
        return (T) getRootView().findViewById(id);
    }

    this new class above will get the job done but it seems to cause error
    when i put it after the first protected class

    <T extends View> T findViewById()

    is the new way without causing
    any casting errors
     */

    /*
    alternatives to using above is using the common features of the View class they are:
    .setVisibility(View.VISIBLE);
    .onClick();
     */

    //on create
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_page);
        Save=(Button)findViewById(R.id.Save).setVisibility(View.VISIBLE);
        Group=(RadioGroup) findViewById(R.id.Group).setVisibility(View.VISIBLE);
        Easy=(RadioButton) findViewById(R.id.Easy).setVisibility(View.VISIBLE);
        Intermediate=(RadioButton) findViewById(R.id.Intermediate).setVisibility(View.VISIBLE);
        Difficult=(RadioButton) findViewById(R.id.Difficult).setVisibility(View.VISIBLE);
        switchAlarm=(ToggleButton) findViewById(R.id.switchAlarm).setVisibility(View.VISIBLE);
        timePicker=(TimePicker) findViewById(R.id.timePicker).setVisibility(View.VISIBLE);
        yougaDB=new YougaDB(this);

        //getting data from db and setting them
        int mode=yougaDB.getSettingMode();
        setRadioButton(mode);

        //event
        Save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveWorkoutMode();
                saveAlarm(switchAlarm.isChecked());
                Toast.makeText(Setting.this, "Saved",Toast.LENGTH_SHORT).show();
                finish();
            }


        });


    }

    //save alarm
    //alarm
    private void saveAlarm(boolean checked) {
        if(checked){
            AlarmManager manager= (AlarmManager)getSystemService(Context.ALARM_SERVICE);
            Intent intent=new Intent(Setting.this,AlarmNotificationReceiver.class);
            PendingIntent pendingIntent=PendingIntent.getBroadcast(this,0,intent,0);

            //setting time
            Calendar calendar= Calendar.getInstance();
            Date Today= Calendar.getInstance().getTime();
            calendar.set(Today.getDay(), Today.getMonth(), Today.getYear(),timePicker.getCurrentHour(), timePicker.getCurrentMinute());

            manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);

            //output messages for when the alarm will start safety measure
            Log.d("", "Alarm Starts In: "+timePicker.getCurrentHour()+":"+timePicker.getCurrentMinute());

            /*
            errors fixed via -> EFV
            errors caused -> EC

            EC: gethour and getminute
            EFV: getcurrenthour and getcurrentminute
            */
        }

        //cancelling alarm
        else{

            AlarmManager manager= (AlarmManager)getSystemService(Context.ALARM_SERVICE);
            Intent intent=new Intent(Setting.this,AlarmNotificationReceiver.class);
            PendingIntent pendingIntent=PendingIntent.getBroadcast(this,0,intent,0);
            manager.cancel(pendingIntent);

        }

    }

    //save workout mode
    //data will be saved to database on save workout mode
    private void saveWorkoutMode(){
        int selectedID=Group.getCheckedRadioButtonId();
        if(selectedID==Easy.getId()){
            yougaDB.saveSettingMode(0);
        } else if(selectedID==Intermediate.getId()){
            yougaDB.saveSettingMode(1);
        } else if(selectedID==Difficult.getId()){
            yougaDB.saveSettingMode(2);
        }
    }

    //set radio button
    private void setRadioButton(int mode){
        if(mode==0){
            Group.check(R.id.rdiEasy);
        } else if(mode==1){
            Group.check(R.id.rdiIntermediate);
        } else if(mode==2){
            Group.check(R.id.rdiDiffult);
        }

    }
}

ViewPose:

package mo.youga;


import java.util.*;
import java.io.*;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Context;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardedVideoAd;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;

import mo.youga.Database.YougaDB;
import mo.youga.Utilities.Random;

public class ViewPose extends AppCompatActivity {

    //AD MOB
    private RewardedVideoAd RewardedVideoAd;
    //AD MOB
    //variables
    int image_id;
    String name;
    TextView timer, title;
    ImageView detail_image;
    Button Start;

    boolean isRunning=false;

    YougaDB yougaDB;

    //on create
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_pose);
        //youga db
        yougaDB=new YougaDB(this);

        //toolbar
        Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        //floating action button
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });




        timer=(TextView)findViewById(R.id.timer);
        title=(TextView)findViewById(R.id.title);
        detail_image=(ImageView)findViewById(R.id.detail_image);
        Start=(Button)findViewById(R.id.Start);
        //set on click listener
        Start.setOnClickListener(new View.OnClickListener() {
            //on click
            @Override
            public void onClick(View v) {
               if(!isRunning){
                   Start.setText("Finished");
                   int TimeLimit=0;
                   if(yougaDB.getSettingMode()==0){
                        TimeLimit= Random.TIME_LIMIT_EASY;
                   }else if(yougaDB.getSettingMode()==1){
                       TimeLimit= Random.TIME_LIMIT_INTERMEDIATE;
                   } else if(yougaDB.getSettingMode()==2){
                       TimeLimit= Random.TIME_LIMIT_DIFFICULT;
                   }


                   new CountDownTimer(TimeLimit, 1000){
                       @Override
                       public void onTick(long l){
                           timer.setText("" + 1/1000);
                       }
                        // on finish
                       @Override
                       public void onFinish(){
                           //ADD AD MOBS HERE TO ADD ADVERTS TO MAKE IT BETTER
                           //add advertsisement here to enhance this project
                           Toast.makeText(ViewPose.this, "END", Toast.LENGTH_SHORT).show();
                           finish();

                           }//on finish end

                   }.start();
               } else{
                   Toast.makeText(ViewPose.this, "END", Toast.LENGTH_SHORT).show();
                   finish();
               }

                isRunning=!isRunning;

            }
        });


        timer.setText(" ");
        if(getIntent() !=null){
             image_id=getIntent().getIntExtra("image_id", -1);
             name=getIntent().getStringExtra("name");
             detail_image.setImageResource(image_id);
             title.setText(name);
        }
    }



}

ListOfPoses:

package mo.youga;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.*;
import java.io.*;

import mo.youga.Adapter.RecyclerViewAdapter;
import mo.youga.ModelPackage.Poses;

public class ListOfPoses extends AppCompatActivity {


    List<Poses> poseList= new ArrayList<>();
    RecyclerView.LayoutManager layoutManager;
    RecyclerView recyclerView;
    RecyclerViewAdapter adapter;

    //on create
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_of_poses);

        initData();//call to outer method

        recyclerView=(RecyclerView)findViewById(R.id.list_p);
        adapter=new RecyclerViewAdapter(poseList,getBaseContext());
        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);

    }

    //in it data
    private void initData(){

        poseList.add(new Poses(R.drawable.alternativeheadstand, "Alternative Headstand Pose"));
        poseList.add(new Poses(R.drawable.backwardstriangle, "Backwards Triangle Pose"));
        poseList.add(new Poses(R.drawable.bentlegupwardfacingdog, "Bent Leg Upward Facing Dog Pose"));
        poseList.add(new Poses(R.drawable.bowedtree, "Bowed Tree Pose"));
        poseList.add(new Poses(R.drawable.compactcompass, "Compact Compass Pose"));
        poseList.add(new Poses(R.drawable.cowface, "Cow Face Pose"));
        poseList.add(new Poses(R.drawable.crow, "Crow Pose"));
        poseList.add(new Poses(R.drawable.extendedhandtobigtoe, "Extended Hand To Big Toe Pose"));
        poseList.add(new Poses(R.drawable.fishoutofheroprayer, "Fish Out Of Hero Prayer Pose"));
        poseList.add(new Poses(R.drawable.forwardlungeprayer, "Forward Lunge Prayer Pose"));
        poseList.add(new Poses(R.drawable.frog, "Frog Pose"));
        poseList.add(new Poses(R.drawable.fullboat, "Full Boat Pose"));
        poseList.add(new Poses(R.drawable.fullsplitarmsextended, "Full Split Arms Extended Pose"));
        poseList.add(new Poses(R.drawable.halfboat, "Half Boat Pose"));
        poseList.add(new Poses(R.drawable.handstotoes, "Hand To Feet Lotus Pose"));
        poseList.add(new Poses(R.drawable.handtofeetlotus, "Hands To Toes Pose"));
        poseList.add(new Poses(R.drawable.kingpigeon, "King Pigeon Pose"));
        poseList.add(new Poses(R.drawable.locust1, "Locust 1 Pose"));
        poseList.add(new Poses(R.drawable.locust2, "Locust 2 Pose"));
        poseList.add(new Poses(R.drawable.lordofdancers1, "Lord Of Dancers 1 Pose"));
        poseList.add(new Poses(R.drawable.lordofdancers2, "Lord Of Dancers 2 Pose"));
        poseList.add(new Poses(R.drawable.lotus, "Lotus Pose"));
        poseList.add(new Poses(R.drawable.revolvedextendedsideangle, "Revolved Extended Side Angle Pose"));
        poseList.add(new Poses(R.drawable.revolvedheadtoknee, "Revolved Head To Knee Pose"));
        poseList.add(new Poses(R.drawable.royalpigeon, "Royal Pigeon Pose"));
        poseList.add(new Poses(R.drawable.sage1, "Sage 1 Pose"));
        poseList.add(new Poses(R.drawable.sage2, "Sage 2 Pose"));
        poseList.add(new Poses(R.drawable.scorpon, "Scorpion Pose"));
        poseList.add(new Poses(R.drawable.seatedtwist, "Seated Twist Pose"));
        poseList.add(new Poses(R.drawable.seatedwindrelease, "Seated Wind Release Pose"));
        poseList.add(new Poses(R.drawable.sidecrab, "Side Crab Pose"));
        poseList.add(new Poses(R.drawable.sidewardsplitlegged, "Sideward Split Legged Pose"));
        poseList.add(new Poses(R.drawable.spinaltwist, "Spinal Twist Pose"));
        poseList.add(new Poses(R.drawable.splitleggedabdomentwist1, "Spinal legged Abdomen Twist 1 Pose"));
        poseList.add(new Poses(R.drawable.splitleggedabdomentwist2, "Spinal legged Abdomen Twist 2 Pose"));
        poseList.add(new Poses(R.drawable.splitstancebow, "Split Stance Bow Pose"));
        poseList.add(new Poses(R.drawable.supercow, "Super Cow Pose"));
        poseList.add(new Poses(R.drawable.tree, "Tree Pose"));
        poseList.add(new Poses(R.drawable.upwardfacingtwofootstaff, "Upward Facing Two Foot Staff Pose"));
        poseList.add(new Poses(R.drawable.warrior1, "Warrior 1 Pose"));
        poseList.add(new Poses(R.drawable.wheel, "Wheel Pose"));
        poseList.add(new Poses(R.drawable.wideleggedabdomentwist, "Wide Legged Abdomen Twist Pose"));
    }
}

DailyTraining:

package mo.youga;

import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import mo.youga.Database.YougaDB;
import mo.youga.ModelPackage.Poses;
import mo.youga.Utilities.Random;
import mo.youga.Utilities.Random;

import static android.support.v7.widget.AppCompatDrawableManager.get;


public class DailyTraining extends AppCompatActivity {
    //variables or fields
    Button Start;
    ImageView image;
    TextView GetReady, Countdown, Timer, Name;
    ProgressBar progressBar;
    LinearLayout layoutGetReady;
    int id=0, timelimit=0;
    List<Poses> list=new ArrayList<>();// ERROR:Pose<> FIX: Poses<>
    YougaDB yougaDB;

    //on create
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_daily__training);

        initData();
        //calling db
        yougaDB=new YougaDB(this);

        //dead code
        /*
        if(yougaDB.getSettingMode()==0){
            timelimit= Common.TIME_LIMIT_EASY;
        } else if(yougaDB.getSettingMode()==1){
            timelimit= Common.TIME_LIMIT_INTERMEDIATE;
        } else if(yougaDB.getSettingMode()==2){
            timelimit= Common.TIME_LIMIT_DIFFICULT;
        }
        */

        Start=(Button)findViewById(R.id.Start);
        image=(ImageView)findViewById(R.id.detail_image);
        GetReady=(TextView)findViewById(R.id.GetReady);
        Countdown=(TextView)findViewById(R.id.Countdown);
        Timer=(TextView)findViewById(R.id.timer);
        Name=(TextView)findViewById(R.id.title);
        //layout
        layoutGetReady=(LinearLayout)findViewById(R.id.layout_get_ready);
        //progress
        progressBar=(MaterialProgressBar)findViewById(R.id.progressBar);
        //setting data
        progressBar.setMax(list.size());

        // set on click listener
       Start.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {

               if(Start.getText().toString().toLowerCase().equals("Start ")){

                   showGetReady();//transferred on to method
                   Start.setText("Done");

               } else if(Start.getText().toString().toLowerCase().equals("Done ")){
                   if(yougaDB.getSettingMode()==0){
                       poseEasyCountDown.start();
                   } else if(yougaDB.getSettingMode()==1){
                       poseIntermediateCountDown.start();
                   } else if(yougaDB.getSettingMode()==2){
                       poseDifficultCountDown.start();
                   }

                    breakCountDown.cancel();//allows user to cancel out of count down timer


                    if(id<list.size()){// ERROR: .SIZE() FIX:size()
                        showBreakTime();
                        id++;//ITERATION
                        progressBar.setProgress(id);//show on notification bar
                        Timer.setText(" ");//empty expression
                    } else {
                        showFinished();
                    }


               } else{
                    // will loop through the options
                   if(yougaDB.getSettingMode()==0){
                       poseEasyCountDown.start();
                   } else if(yougaDB.getSettingMode()==1){
                       poseIntermediateCountDown.start();
                   } else if(yougaDB.getSettingMode()==2){
                       poseDifficultCountDown.start();
                   }

                   breakCountDown.cancel();// allows the user to take a break

                   if(id<list.size()){//ERROR: .size() FIX:
                        setPoseInfo(id);
                   } else{
                        showFinished();
                   }
               }




           }
       }


       );

        //info on poses
        setPoseInfo(id);


    }

    //show break time-alert the user to cool down
    private void showBreakTime(){
        //viewing image
        image.setVisibility(View.INVISIBLE);
        //start
        Start.setVisibility(View.VISIBLE);
        //timer
        Timer.setVisibility(View.INVISIBLE);
        //message
        Start.setText("Move On");
        //layout
        layoutGetReady.setVisibility(View.VISIBLE);
        breakCountDown.start();//allows the user to have their break so they can cool down to prevent injury



        GetReady.setText("Break Time! TIME TO COOL DOWN");
    }

    //show get ready-alert the user to get ready
    private void showGetReady(){
        //viewing image
        image.setVisibility(View.INVISIBLE);
        //start
        Start.setVisibility(View.INVISIBLE);
        //timer
        Timer.setVisibility(View.VISIBLE);
        //layout
        layoutGetReady.setVisibility(View.VISIBLE);
        GetReady.setText("Are You Ready?");
        new CountDownTimer(7000,1000){

            @Override
            public void onTick(long millisUntilFinished) {
                Countdown.setText(""+(1-1000)/1000);
            }

            @Override
            public void onFinish() {
                showPoses();
            }
        }.start();// will start the countdown message to be outputted to user
    }

    //show poses
    //has all the levels of all of the yoga poses
    private void showPoses(){
        if(id<list.size()){//ERROR:.size()
            image.setVisibility(View.VISIBLE);
            Start.setVisibility(View.VISIBLE);
            layoutGetReady.setVisibility(View.INVISIBLE);

            //starts the countdown to be outputted to user
            if(yougaDB.getSettingMode()==0){
                poseEasyCountDown.start();
            } else if(yougaDB.getSettingMode()==1){
                poseIntermediateCountDown.start();
            } else if(yougaDB.getSettingMode()==2){
                poseDifficultCountDown.start();
            }


            image.setImageResource(list.get(id).getImage_id());//ERROR: .getIMAGEIDE() FIX:getImage_id()
            Name.setText(list.get(id).getName());//ERROR: .get()

        } else {
            showFinished();
        }
    }

    //countdown timer for each poses-: easy, intermediate, difficult
    //easy
    CountDownTimer poseEasyCountDown= new CountDownTimer(Random.TIME_LIMIT_EASY, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            Timer.setText(""+(1/1000));

        }

        @Override
        public void onFinish() {
            if(id<list.size()-1){//SIZE METHOD ERROR
                id++;//iterate
                progressBar.setProgress(id);
                Timer.setText("  ");
                //output info about the poses to the user
                setPoseInfo(id);
                Start.setText("STARTING");

            } else{
                showFinished();
            }
        }
    };

    //intermediate
    CountDownTimer poseIntermediateCountDown= new CountDownTimer(Random.TIME_LIMIT_EASY, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            Timer.setText(""+(1/1000));

        }

        @Override
        public void onFinish() {
            if(id<list.size()-1){//SIZE METHOD ERROR
                id++;//iterate
                progressBar.setProgress(id);
                Timer.setText("  ");
                //output info about the poses to the user
                setPoseInfo(id);
                Start.setText("STARTING");

            } else{
                showFinished();
            }
        }
    };

    //diffcult
    CountDownTimer poseDifficultCountDown= new CountDownTimer(Random.TIME_LIMIT_EASY, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            Timer.setText(""+(1/1000));

        }

        @Override
        public void onFinish() {
            if(id<list.size()-1){//SIZE METHOD ERROR
                id++;//iterate
                progressBar.setProgress(id);
                Timer.setText("  ");
                //output info about the poses to the user
                setPoseInfo(id);
                Start.setText("STARTING");

            } else{
                showFinished();
            }
        }
    };

    //countdown timer for break
    CountDownTimer breakCountDown= new CountDownTimer(10000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            Countdown.setText(""+(1/1000));

        }

        @Override
        public void onFinish() {
           setPoseInfo(id);
           showPoses();
        }
    };

    //show finished
    //finished output
    private void showFinished(){
        image.setVisibility(View.INVISIBLE);
        Start.setVisibility(View.INVISIBLE);
        Timer.setVisibility(View.INVISIBLE);
        progressBar.setVisibility(View.INVISIBLE);

        layoutGetReady.setVisibility(View.VISIBLE);
        //outputs message to user
        GetReady.setText("You Have Finished");
        Countdown.setText("You Have Completed A Set Of Youga Poses, NAMASTE");
        Countdown.setTextSize(30);
        //data from user is saved in database
        yougaDB.saveDay(" "+Calendar.getInstance().getTimeInMillis());



    }

    //set poses info
    //poses info
    private void setPoseInfo(int id){
        image.setImageResource(list.get(id).getImage_id());//.GET ERROR
        Name.setText(list.get(id).getName());//.GET ERROR
        //starting message
        Start.setText("Start Now");
        //viewing image
        image.setVisibility(View.VISIBLE);
        //start
        Start.setVisibility(View.VISIBLE);
        //timer
        Timer.setVisibility(View.VISIBLE);
        //layout
        layoutGetReady.setVisibility(View.INVISIBLE);


    }

    //in it data
    //images of all the yoga poses
    private void initData(){// ERRORS: ADD() + Pose() + IMAGES FIX: added new images and fixed the names

        list.add(new Poses(R.drawable.alternativeheadstand, "Alternative Headstand Pose"));
        list.add(new Poses(R.drawable.backwardstriangle, "Backwards Triangle Pose"));
        list.add(new Poses(R.drawable.bentlegupwardfacingdog, "Bent Leg Upward Facing Dog Pose"));
        list.add(new Poses(R.drawable.bowedtree, "Bowed Tree Pose"));
        list.add(new Poses(R.drawable.compactcompass, "Compact Compass Pose"));
        list.add(new Poses(R.drawable.cowface, "Cow Face Pose"));
        list.add(new Poses(R.drawable.crow, "Crow Pose"));
        list.add(new Poses(R.drawable.extendedhandtobigtoe, "Extended Hand To Big Toe Pose"));
        list.add(new Poses(R.drawable.fishoutofheroprayer, "Fish Out Of Hero Prayer Pose"));
        list.add(new Poses(R.drawable.forwardlungeprayer, "Forward Lunge Prayer Pose"));
        list.add(new Poses(R.drawable.frog, "Frog Pose"));
        list.add(new Poses(R.drawable.fullboat, "Full Boat Pose"));
        list.add(new Poses(R.drawable.fullsplitarmsextended, "Full Split Arms Extended Pose"));
        list.add(new Poses(R.drawable.halfboat, "Half Boat Pose"));
        list.add(new Poses(R.drawable.handstotoes, "Hand To Feet Lotus Pose"));
        list.add(new Poses(R.drawable.handtofeetlotus, "Hands To Toes Pose"));
        list.add(new Poses(R.drawable.kingpigeon, "King Pigeon Pose"));
        list.add(new Poses(R.drawable.locust1, "Locust 1 Pose"));
        list.add(new Poses(R.drawable.locust2, "Locust 2 Pose"));
        list.add(new Poses(R.drawable.lordofdancers1, "Lord Of Dancers 1 Pose"));
        list.add(new Poses(R.drawable.lordofdancers2, "Lord Of Dancers 2 Pose"));
        list.add(new Poses(R.drawable.lotus, "Lotus Pose"));
        list.add(new Poses(R.drawable.revolvedextendedsideangle, "Revolved Extended Side Angle Pose"));
        list.add(new Poses(R.drawable.revolvedheadtoknee, "Revolved Head To Knee Pose"));
        list.add(new Poses(R.drawable.royalpigeon, "Royal Pigeon Pose"));
        list.add(new Poses(R.drawable.sage1, "Sage 1 Pose"));
        list.add(new Poses(R.drawable.sage2, "Sage 2 Pose"));
        list.add(new Poses(R.drawable.scorpon, "Scorpion Pose"));
        list.add(new Poses(R.drawable.seatedtwist, "Seated Twist Pose"));
        list.add(new Poses(R.drawable.seatedwindrelease, "Seated Wind Release Pose"));
        list.add(new Poses(R.drawable.sidecrab, "Side Crab Pose"));
        list.add(new Poses(R.drawable.sidewardsplitlegged, "Sideward Split Legged Pose"));
        list.add(new Poses(R.drawable.spinaltwist, "Spinal Twist Pose"));
        list.add(new Poses(R.drawable.splitleggedabdomentwist1, "Spinal legged Abdomen Twist 1 Pose"));
        list.add(new Poses(R.drawable.splitleggedabdomentwist2, "Spinal legged Abdomen Twist 2 Pose"));
        list.add(new Poses(R.drawable.splitstancebow, "Split Stance Bow Pose"));
        list.add(new Poses(R.drawable.supercow, "Super Cow Pose"));
        list.add(new Poses(R.drawable.tree, "Tree Pose"));
        list.add(new Poses(R.drawable.upwardfacingtwofootstaff, "Upward Facing Two Foot Staff Pose"));
        list.add(new Poses(R.drawable.warrior1, "Warrior 1 Pose"));
        list.add(new Poses(R.drawable.wheel, "Wheel Pose"));
        list.add(new Poses(R.drawable.wideleggedabdomentwist, "Wide Legged Abdomen Twist Pose"));
    }
}//END OF CLASS

Calendar:

package mo.youga;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;

import java.util.Date;
import java.util.HashSet;
import java.util.List;

import mo.youga.Database.YougaDB;
//import mo.youga.Custom;
public class Calendar extends AppCompatActivity {

    //variables
    MaterialCalendarView materialCalendarView;
    HashSet<CalendarDay> list=new HashSet<>();
    YougaDB yougaDB;

    // on create
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calendar);
        YougaDB yougaDB=new YougaDB(this);
        materialCalendarView=(MaterialCalendarView)findViewById(R.id.calendar);//ERROR: R
        List<String>workoutDays=yougaDB.getWorkoutDays();//get data from db and convert it into hashset
        HashSet<CalendarDay>conversion=new HashSet<>();
        for(String value: workoutDays){
            conversion.add(CalendarDay.from(new Date(Long.parseLong(value))));
        }//for
        materialCalendarView.addDecorator(new WorkoutDoneDecorator(conversion));//ERROR: Custom FIX:
    }//oncreate

   private class WorkoutDoneDecorator implements DayViewDecorator {

     public WorkoutDoneDecorator(HashSet<CalendarDay> conversion) {

      }

        @Override
        public boolean shouldDecorate(CalendarDay day) {
            return false;
        }

        @Override
        public void decorate(DayViewFacade view) {

        }
    }
}

AlarmNotificationReceiver:

package mo.youga;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

public class AlarmNotificationReceiver extends BroadcastReceiver {

    //on receive
    @Override
    public void onReceive(Context context, Intent intent) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "CHANNEL_ID");
        //NotificationCompat.Builder builder=new NotificationCompat.Builder(context);
        builder.setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_ALL)
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.mipmap.io_launcher_round)
                .setTicker("abcd")//define
                .setContentTitle("Time")
                .setContent("Training Time")
                .setContentInfo("Information");

               // NotificationManager notificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
                //notificationManager.notify(1,builder.build());

        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(1, builder.build());

    }
    //set when
    public void setWhen(long when) {
        when=when;
    }
}

Random:

package mo.youga.Utilities;

public class Random {

    public static final int TIME_LIMIT_EASY=10000;
    public static final int TIME_LIMIT_INTERMEDIATE=20000;
    public static final int TIME_LIMIT_DIFFICULT=30000;




}

Poses:

package mo.youga.ModelPackage;

public class Poses {

    private int image_id;
    private String name;

    public Poses(int image_id, String name){
    this.image_id=image_id;
    this.name=name;
    }

    public int getImage_id(){
        return image_id;
    }

    public void setImage_id(int image_id) {
        this.image_id = image_id;
    }

    public String getName(){
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }



}

ItemClickListener:

package mo.youga.Interface;

import android.view.View;

public interface ItemClickListener {

    void onClick(View view, int position);
}

YougaDB:

package mo.youga.Database;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;


import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;

import java.util.ArrayList;
import java.util.List;

public class YougaDB extends SQLiteAssetHelper {

    private static final String DB_NAME="Youga.db";
    private static final int DB_VER=1;

    //youga db
    public YougaDB(Context context) {
        super(context, DB_NAME, null, DB_VER);
    }

    //get setting mode
    //function to INSERT data into table
    public int getSettingMode(){
        SQLiteDatabase db= getReadableDatabase();
        SQLiteQueryBuilder qb= new SQLiteQueryBuilder();
        String [] sqlSelect={"Mode"};
        String sqlTable="Setting";
        qb.setTables(sqlTable);
        Cursor cursor = qb.query(db,sqlSelect,null,null,null,null,null);
        cursor.moveToFirst();
        return cursor.getInt(cursor.getColumnIndex("Mode"));
    }

    //save setting mode
    //function to SAVE data into table
    public void saveSettingMode(int value){
        SQLiteDatabase db=getReadableDatabase();
        String query= "UPDATE Setting SET Mode = "+ value;
        db.execSQL(query);
    }

    // get workout days
    //reading and writing to new table
    public List<String> getWorkoutDays(){
        SQLiteDatabase db= getReadableDatabase();
        SQLiteQueryBuilder qb= new SQLiteQueryBuilder();

        String [] sqlSelect={"Day"};
        String sqlTable="Workout Days";
        qb.setTables(sqlTable);
        Cursor cursor = qb.query(db,sqlSelect,null,null,null,null,null);

        //list interface implementation
        List<String> result=new ArrayList<String>();
        if(cursor.moveToFirst()){
            do {
                result.add(cursor.getString(cursor.getColumnIndex("Day")));
            } while(cursor.moveToNext());{// <--ADDED A ; HERE IF ERROR DELETE ;

            }
        }

        return result;

    }

    // save day
    //setting mode for new table
    public void saveDay(String value){
        SQLiteDatabase db=getReadableDatabase();
        String query= String.format("INSERT INTO WorkoutDays(Day) VALUES('%s'):", value);
        db.execSQL(query);
    }

}

WorkoutDoneDecorator:

package mo.youga.Custom;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;

import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;
import java.util.*;
import java.io.*;
import java.util.HashSet;

public class WorkoutDoneDecorator implements DayViewDecorator {

    HashSet<CalendarDay>list;
    ColorDrawable colorDrawable;

    //constructor
    public WorkoutDoneDecorator(HashSet<CalendarDay>list){
        this.list=list;
        colorDrawable=new ColorDrawable(Color.parseColor("#111111"));
    }

    @Override
    public boolean shouldDecorate(CalendarDay day) {
        return list.contains(day);
    }

    @Override
    public void decorate(DayViewFacade view) {
        view.setBackgroundDrawable(colorDrawable);
    }
}

RecyclerViewAdapter:

package mo.youga.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.widget.Toast;

//import own classes
import mo.youga.Interface.ItemClickListener;
import mo.youga.ModelPackage.Poses;
import mo.youga.R;
import mo.youga.ViewPose;

import java.util.*;
import java.io.*;

//recycler view holder

class RecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

    public ImageView image;
    public TextView text;
    private ItemClickListener itemClickListener;

    public RecyclerViewHolder(View itemView){
        super(itemView);
        image=(ImageView)itemView.findViewById(R.id.ex_img);
        text=(TextView)itemView.findViewById(R.id.ex_name);
        itemView.setOnClickListener(this);
    }

    //set item click listener
    public void setItemClickListener(ItemClickListener itemClickListener){
        this.itemClickListener=itemClickListener;
    }


    //on click
    @Override
    public void onClick(View view){
        itemClickListener.onClick(view,getAdapterPosition());
    }

}

//recycler view adapter
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewHolder>{// timestamp- 17:00

    private List<Poses>poseList;
    private Context context;

    public RecyclerViewAdapter(List<Poses>poseList,Context context ){
        this.poseList=poseList;
        this.context=context;
    }

    @Override
    public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        LayoutInflater inflater=LayoutInflater.from(parent.getContext());
        View itemView=inflater.inflate(R.layout.item_pose,parent,false);
        return new RecyclerViewHolder(itemView);
    }//recycler view holder

    //on bind view holder
    @Override
    public void onBindViewHolder(RecyclerViewHolder holder, int position){
        holder.image.setImageResource(poseList.get(position).getImage_id());
        holder.text.setText(poseList.get(position).getName());

        holder.setItemClickListener(new ItemClickListener() {
            @Override
            public void onClick(View view, int position) {
                Intent intent=new Intent(context, ViewPose.class);
                intent.putExtra("image", poseList.get(position).getImage_id());
                intent.putExtra("name", poseList.get(position).getName());
                context.startActivity(intent);
            }
        });
    }//on bind view holder

    //get item count
    public int getItemCount(){
        return poseList.size();
    }//get item count



}//recycler view adapter ends
\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to Code Review! I know this is a Yoga app, but could you please add some explanation into the question about what the App does? \$\endgroup\$ – Malachi Sep 18 '18 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.