Write Android app program for cake order and delivery to customers

 It would be a complex task to write a complete program for an Android app for cake ordering and delivery, as it would involve many different components and programming concepts. However, I can provide you an example in pseudocode that describes some of the main features of the app and how they could be implemented.


// MainActivity.java - the main activity of the app

public class MainActivity extends AppCompatActivity {

    // global variables
    private RecyclerView cakeListView;
    private CakeAdapter cakeAdapter;
    private List<Cake> cakes;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // initializing global variables
        cakeListView = findViewById(R.id.cake_list);
        cakes = new ArrayList<>();
        cakeAdapter = new CakeAdapter(this, cakes);
        cakeListView.setAdapter(cakeAdapter);
        cakeListView.setLayoutManager(new LinearLayoutManager(this));

        // Retrieve the list of cakes from the server
        new GetCakesTask().execute();

        // when user clicks on a cake, start the CakeDetailActivity
        cakeListView.addOnItemTouchListener(new RecyclerTouchListener(this, cakeListView, new ClickListener() {
            @Override
            public void onClick(View view, int position) {
                Cake cake = cakes.get(position);
                Intent intent = new Intent(MainActivity.this, CakeDetailActivity.class);
                intent.putExtra("cake", cake);
                startActivity(intent);
            }
        }));
    }

    private class GetCakesTask extends AsyncTask<Void, Void, List<Cake>> {

        @Override
        protected List<Cake> doInBackground(Void... voids) {
            // retrieve the list of cakes from the server
            //using some http library 
            return cakes;
        }

        @Override
        protected void onPostExecute(List<Cake> cakes) {
            MainActivity.this.cakes.clear();
            MainActivity.this.cakes.addAll(cakes);
            cakeAdapter.notifyDataSetChanged();
        }
    }
}

// CakeDetailActivity.java - the activity that displays the details of a cake

public class CakeDetailActivity extends AppCompatActivity {

    private Cake cake;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cake_detail);

        // get the cake from the intent
        cake = getIntent().getParcelableExtra("cake");

        // set the details of the cake in the UI
        ImageView cakeImage = findViewById(R.id.cake_image);
        TextView cakeName = findViewById(R.id.cake_name);
        TextView cakeDescription = findViewById(R.id.cake_description);
        TextView cakePrice = findViewById(R.id.cake_price);

        cakeImage.setImageBitmap(cake.getImage());
        cakeName.setText(cake.getName());
        cakeDescription.setText(cake.getDescription());



Comments